Skip to content

Commit 3d270f1

Browse files
committed
go: upgrade to Go 1.26.4 and run go fix ./...
1 parent 4756698 commit 3d270f1

15 files changed

Lines changed: 57 additions & 64 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
go:
17-
- 1.16
17+
- 1.26.4
1818
name: Go ${{ matrix.go }}
1919
runs-on: ubuntu-latest
2020
steps:

call_opt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func (c callOptionFunc) apply(r *Request) error { return c(r) }
1313
// Meta returns a call option which attaches the given meta object to
1414
// the JSON-RPC 2.0 request (this is a Sourcegraph extension to JSON
1515
// RPC 2.0 for carrying metadata).
16-
func Meta(meta interface{}) CallOption {
16+
func Meta(meta any) CallOption {
1717
return callOptionFunc(func(r *Request) error {
1818
return r.SetMeta(meta)
1919
})
@@ -22,7 +22,7 @@ func Meta(meta interface{}) CallOption {
2222
// ExtraField returns a call option which attaches the given name/value pair to
2323
// the JSON-RPC 2.0 request. This can be used to add arbitrary extensions to
2424
// JSON RPC 2.0.
25-
func ExtraField(name string, value interface{}) CallOption {
25+
func ExtraField(name string, value any) CallOption {
2626
return callOptionFunc(func(r *Request) error {
2727
return r.SetExtraField(name, value)
2828
})

call_opt_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import (
99
)
1010

1111
func TestPickID(t *testing.T) {
12-
ctx, cancel := context.WithCancel(context.Background())
13-
defer cancel()
12+
ctx := t.Context()
1413

1514
a, b := inMemoryPeerConns()
1615
defer a.Close()
@@ -27,7 +26,7 @@ func TestPickID(t *testing.T) {
2726
defer connB.Close()
2827

2928
const n = 100
30-
for i := 0; i < n; i++ {
29+
for i := range n {
3130
var opts []jsonrpc2.CallOption
3231
id := jsonrpc2.ID{Num: uint64(i)}
3332

@@ -54,8 +53,7 @@ func TestPickID(t *testing.T) {
5453

5554
func TestStringID(t *testing.T) {
5655

57-
ctx, cancel := context.WithCancel(context.Background())
58-
defer cancel()
56+
ctx := t.Context()
5957

6058
a, b := inMemoryPeerConns()
6159
defer a.Close()
@@ -93,8 +91,7 @@ func TestStringID(t *testing.T) {
9391

9492
func TestExtraField(t *testing.T) {
9593

96-
ctx, cancel := context.WithCancel(context.Background())
97-
defer cancel()
94+
ctx := t.Context()
9895

9996
a, b := inMemoryPeerConns()
10097
defer a.Close()

conn.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (c *Conn) Close() error {
8686
// waits for the response. If the response is successful, its result is stored
8787
// in result (a pointer to a value that can be JSON-unmarshaled into);
8888
// otherwise, a non-nil error is returned. See DispatchCall for more details.
89-
func (c *Conn) Call(ctx context.Context, method string, params, result interface{}, opts ...CallOption) error {
89+
func (c *Conn) Call(ctx context.Context, method string, params, result any, opts ...CallOption) error {
9090
call, err := c.DispatchCall(ctx, method, params, opts...)
9191
if err != nil {
9292
return err
@@ -108,7 +108,7 @@ func (c *Conn) DisconnectNotify() <-chan struct{} {
108108
// The params member is omitted from the JSON-RPC request if the given params is
109109
// nil. Use json.RawMessage("null") to send a JSON-RPC request with its params
110110
// member set to null.
111-
func (c *Conn) DispatchCall(ctx context.Context, method string, params interface{}, opts ...CallOption) (Waiter, error) {
111+
func (c *Conn) DispatchCall(ctx context.Context, method string, params any, opts ...CallOption) (Waiter, error) {
112112
req := &Request{Method: method}
113113
for _, opt := range opts {
114114
if opt == nil {
@@ -137,7 +137,7 @@ func (c *Conn) DispatchCall(ctx context.Context, method string, params interface
137137
// The params member is omitted from the JSON-RPC request if the given params is
138138
// nil. Use json.RawMessage("null") to send a JSON-RPC request with its params
139139
// member set to null.
140-
func (c *Conn) Notify(ctx context.Context, method string, params interface{}, opts ...CallOption) error {
140+
func (c *Conn) Notify(ctx context.Context, method string, params any, opts ...CallOption) error {
141141
req := &Request{Method: method, Notif: true}
142142
for _, opt := range opts {
143143
if opt == nil {
@@ -157,7 +157,7 @@ func (c *Conn) Notify(ctx context.Context, method string, params interface{}, op
157157
}
158158

159159
// Reply sends a successful response with a result.
160-
func (c *Conn) Reply(ctx context.Context, id ID, result interface{}) error {
160+
func (c *Conn) Reply(ctx context.Context, id ID, result any) error {
161161
resp := &Response{ID: id}
162162
if err := resp.SetResult(result); err != nil {
163163
return err
@@ -346,7 +346,7 @@ type Waiter struct {
346346
// is successful, its result is stored in result (a pointer to a
347347
// value that can be JSON-unmarshaled into); otherwise, a non-nil
348348
// error is returned.
349-
func (w Waiter) Wait(ctx context.Context, result interface{}) error {
349+
func (w Waiter) Wait(ctx context.Context, result any) error {
350350
select {
351351
case <-ctx.Done():
352352
return ctx.Err()
@@ -380,7 +380,7 @@ type anyMessage struct {
380380
}
381381

382382
func (m anyMessage) MarshalJSON() ([]byte, error) {
383-
var v interface{}
383+
var v any
384384
switch {
385385
case m.request != nil && m.response == nil:
386386
v = m.request
@@ -397,10 +397,10 @@ func (m *anyMessage) UnmarshalJSON(data []byte) error {
397397
// The presence of these fields distinguishes between the 2
398398
// message types.
399399
type msg struct {
400-
ID interface{} `json:"id"`
400+
ID any `json:"id"`
401401
Method *string `json:"method"`
402402
Result anyValueWithExplicitNull `json:"result"`
403-
Error interface{} `json:"error"`
403+
Error any `json:"error"`
404404
}
405405

406406
var isRequest, isResponse bool
@@ -441,7 +441,7 @@ func (m *anyMessage) UnmarshalJSON(data []byte) error {
441441
}
442442
}
443443

444-
var v interface{}
444+
var v any
445445
switch {
446446
case isRequest && !isResponse:
447447
v = &m.request
@@ -461,7 +461,7 @@ func (m *anyMessage) UnmarshalJSON(data []byte) error {
461461
// {"result":null} by anyMessage's JSON unmarshaler.
462462
type anyValueWithExplicitNull struct {
463463
null bool // JSON "null"
464-
value interface{}
464+
value any
465465
}
466466

467467
func (v anyValueWithExplicitNull) MarshalJSON() ([]byte, error) {

conn_opt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
// Logger interface implements one method - Printf.
99
// You can use the stdlib logger *log.Logger
1010
type Logger interface {
11-
Printf(format string, v ...interface{})
11+
Printf(format string, v ...any)
1212
}
1313

1414
// ConnOpt is the type of function that can be passed to NewConn to

conn_opt_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ import (
1212
)
1313

1414
func TestSetLogger(t *testing.T) {
15-
ctx, cancel := context.WithCancel(context.Background())
16-
defer cancel()
15+
ctx := t.Context()
1716

1817
rd, wr := io.Pipe()
1918
defer rd.Close()
@@ -67,8 +66,7 @@ func (h *dummyHandler) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jso
6766
}
6867

6968
func TestLogMessages(t *testing.T) {
70-
ctx, cancel := context.WithCancel(context.Background())
71-
defer cancel()
69+
ctx := t.Context()
7270

7371
rd, wr := io.Pipe()
7472
defer rd.Close()

conn_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestConn(t *testing.T) {
6767
}
6868

6969
var paramsTests = []struct {
70-
sendParams interface{}
70+
sendParams any
7171
wantParams *json.RawMessage
7272
}{
7373
{
@@ -220,8 +220,7 @@ func TestConn_Close(t *testing.T) {
220220
}}
221221
for _, tc := range cases {
222222
t.Run(tc.name, func(t *testing.T) {
223-
ctx, cancel := context.WithCancel(context.Background())
224-
defer cancel()
223+
ctx := t.Context()
225224

226225
connA, connB := net.Pipe()
227226
nodeA := jsonrpc2.NewConn(

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module github.com/sourcegraph/jsonrpc2
22

3-
go 1.12
3+
go 1.26.4
44

55
require github.com/gorilla/websocket v1.4.1

handler_with_error.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ import (
66

77
// HandlerWithError implements Handler by calling the func for each
88
// request and handling returned errors and results.
9-
func HandlerWithError(handleFunc func(context.Context, *Conn, *Request) (result interface{}, err error)) *HandlerWithErrorConfigurer {
9+
func HandlerWithError(handleFunc func(context.Context, *Conn, *Request) (result any, err error)) *HandlerWithErrorConfigurer {
1010
return &HandlerWithErrorConfigurer{handleFunc: handleFunc}
1111
}
1212

1313
// HandlerWithErrorConfigurer is a handler created by HandlerWithError.
1414
type HandlerWithErrorConfigurer struct {
15-
handleFunc func(context.Context, *Conn, *Request) (result interface{}, err error)
15+
handleFunc func(context.Context, *Conn, *Request) (result any, err error)
1616
suppressErrClosed bool
1717
}
1818

jsonrpc2.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import (
1616
// an API boundary.
1717
type JSONRPC2 interface {
1818
// Call issues a standard request (http://www.jsonrpc.org/specification#request_object).
19-
Call(ctx context.Context, method string, params, result interface{}, opt ...CallOption) error
19+
Call(ctx context.Context, method string, params, result any, opt ...CallOption) error
2020

2121
// Notify issues a notification request (http://www.jsonrpc.org/specification#notification).
22-
Notify(ctx context.Context, method string, params interface{}, opt ...CallOption) error
22+
Notify(ctx context.Context, method string, params any, opt ...CallOption) error
2323

2424
// Close closes the underlying connection, if it exists.
2525
Close() error
@@ -34,7 +34,7 @@ type Error struct {
3434

3535
// SetError sets e.Data to the JSON encoding of v. If JSON
3636
// marshaling fails, it panics.
37-
func (e *Error) SetError(v interface{}) {
37+
func (e *Error) SetError(v any) {
3838
b, err := json.Marshal(v)
3939
if err != nil {
4040
panic("Error.SetData: " + err.Error())

0 commit comments

Comments
 (0)