Skip to content

Commit 79f2c21

Browse files
committed
Allow 'nil' as an alias of []any{} in SendRequest/Notification
1 parent de76b1a commit 79f2c21

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

msgpackrpc/connection.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ func (c *Connection) Close() {
301301
}
302302

303303
func (c *Connection) SendRequest(ctx context.Context, method string, params []any) (reqResult any, reqError any, err error) {
304+
if params == nil {
305+
params = []any{}
306+
}
307+
304308
id := MessageID(c.lastOutRequestsIndex.Add(1))
305309

306310
c.loggerMutex.Lock()
@@ -352,6 +356,10 @@ func (c *Connection) SendRequest(ctx context.Context, method string, params []an
352356
}
353357

354358
func (c *Connection) SendNotification(method string, params []any) error {
359+
if params == nil {
360+
params = []any{}
361+
}
362+
355363
c.loggerMutex.Lock()
356364
c.logger.LogOutgoingNotification(method, params)
357365
c.loggerMutex.Unlock()

0 commit comments

Comments
 (0)