Skip to content

Upgrade go version #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ jobs:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: golangci/golangci-lint-action@v3
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: golangci/golangci-lint-action@55c2c1448f86e01eaae002a5a3a9624417608d84 # v6.5.2
with:
version: v1.52.2
version: v1.64.8
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
go: [ 'stable', 'oldstable' ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5.4.0
with:
go-version: ${{ matrix.go }}
cache: true
- run: go test -race -covermode=atomic -coverprofile=coverage.txt ./...
- uses: codecov/codecov-action@v3
- uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5.4.0
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
linters-settings:
errcheck:
check-type-asserts: true
check-type-assertions: true
check-blank: true
misspell:
locale: US
Expand All @@ -11,7 +11,7 @@ linters:
- varnamelen
- wsl
- exhaustruct
- exhaustivestruct
- depguard

issues:
exclude-rules:
Expand Down
6 changes: 3 additions & 3 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type (

// RequestID takes request id from context.
func RequestID(c context.Context) *json.RawMessage {
v, _ := c.Value(requestIDKey{}).(*json.RawMessage)
v, _ := c.Value(requestIDKey{}).(*json.RawMessage) //nolint: errcheck

return v
}
Expand All @@ -26,7 +26,7 @@ func WithRequestID(c context.Context, id *json.RawMessage) context.Context {

// GetMetadata takes jsonrpc metadata from context.
func GetMetadata(c context.Context) Metadata {
v, _ := c.Value(metadataIDKey{}).(Metadata)
v, _ := c.Value(metadataIDKey{}).(Metadata) //nolint: errcheck

return v
}
Expand All @@ -38,7 +38,7 @@ func WithMetadata(c context.Context, md Metadata) context.Context {

// MethodName takes method name from context.
func MethodName(c context.Context) string {
v, _ := c.Value(methodNameKey{}).(string)
v, _ := c.Value(methodNameKey{}).(string) //nolint: errcheck

return v
}
Expand Down
10 changes: 3 additions & 7 deletions context_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jsonrpc_test

import (
"context"
"testing"

"github.com/goccy/go-json"
Expand All @@ -12,9 +11,8 @@ import (
func TestRequestID(t *testing.T) {
t.Parallel()

c := context.Background()
id := json.RawMessage("1")
c = jsonrpc.WithRequestID(c, &id)
c := jsonrpc.WithRequestID(t.Context(), &id)
var pick *json.RawMessage
require.NotPanics(t, func() {
pick = jsonrpc.RequestID(c)
Expand All @@ -25,9 +23,8 @@ func TestRequestID(t *testing.T) {
func TestMetadata(t *testing.T) {
t.Parallel()

c := context.Background()
md := jsonrpc.Metadata{Params: jsonrpc.Metadata{}}
c = jsonrpc.WithMetadata(c, md)
c := jsonrpc.WithMetadata(t.Context(), md)
var pick jsonrpc.Metadata
require.NotPanics(t, func() {
pick = jsonrpc.GetMetadata(c)
Expand All @@ -38,8 +35,7 @@ func TestMetadata(t *testing.T) {
func TestMethodName(t *testing.T) {
t.Parallel()

c := context.Background()
c = jsonrpc.WithMethodName(c, t.Name())
c := jsonrpc.WithMethodName(t.Context(), t.Name())
var pick string
require.NotPanics(t, func() {
pick = jsonrpc.MethodName(c)
Expand Down
5 changes: 2 additions & 3 deletions debug_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package jsonrpc_test

import (
"context"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -17,7 +16,7 @@ func TestDebugHandler(t *testing.T) {
mr := jsonrpc.NewMethodRepository()

rec := httptest.NewRecorder()
r, err := http.NewRequestWithContext(context.Background(), "", "", nil)
r, err := http.NewRequestWithContext(t.Context(), "", "", nil)
require.NoError(t, err)

mr.ServeDebug(rec, r)
Expand All @@ -31,7 +30,7 @@ func TestDebugHandler(t *testing.T) {
}{}))

rec = httptest.NewRecorder()
r, err = http.NewRequestWithContext(context.Background(), "", "", nil)
r, err = http.NewRequestWithContext(t.Context(), "", "", nil)
require.NoError(t, err)

mr.ServeDebug(rec, r)
Expand Down
15 changes: 10 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
module github.com/osamingo/jsonrpc/v2

go 1.18
go 1.24

toolchain go1.24.1

require (
github.com/goccy/go-json v0.10.0
github.com/invopop/jsonschema v0.7.0
github.com/stretchr/testify v1.8.2
github.com/goccy/go-json v0.10.5
github.com/invopop/jsonschema v0.13.0
github.com/stretchr/testify v1.10.0
)

require (
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/iancoleman/orderedmap v0.1.0 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
31 changes: 14 additions & 17 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA=
github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
github.com/iancoleman/orderedmap v0.1.0 h1:2orAxZBJsvimgEBmMWfXaFlzSG2fbQil5qzP3F6cCkg=
github.com/iancoleman/orderedmap v0.1.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
github.com/invopop/jsonschema v0.7.0 h1:2vgQcBz1n256N+FpX3Jq7Y17AjYt46Ig3zIWyy770So=
github.com/invopop/jsonschema v0.7.0/go.mod h1:O9uiLokuu0+MGFlyiaqtWxwqJm41/+8Nj0lD7A36YH0=
github.com/goccy/go-json v0.10.5 h1:Fq85nIqj+gXn/S5ahsiTlK3TmC85qgirsdTP/+DeaC4=
github.com/goccy/go-json v0.10.5/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.3.1-0.20190311161405-34c6fa2dc709/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
12 changes: 6 additions & 6 deletions handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestHandler(t *testing.T) {
mr := jsonrpc.NewMethodRepository()

rec := httptest.NewRecorder()
r, err := http.NewRequestWithContext(context.Background(), "", "", nil)
r, err := http.NewRequestWithContext(t.Context(), "", "", nil)
require.NoError(t, err)

mr.ServeHTTP(rec, r)
Expand All @@ -30,7 +30,7 @@ func TestHandler(t *testing.T) {
assert.NotNil(t, res.Error)

rec = httptest.NewRecorder()
r, err = http.NewRequestWithContext(context.Background(), "", "", bytes.NewReader([]byte(`{"jsonrpc":"2.0","id":"test","method":"hello","params":{}}`)))
r, err = http.NewRequestWithContext(t.Context(), "", "", bytes.NewReader([]byte(`{"jsonrpc":"2.0","id":"test","method":"hello","params":{}}`)))
require.NoError(t, err)
r.Header.Set("Content-Type", "application/json")

Expand All @@ -40,17 +40,17 @@ func TestHandler(t *testing.T) {
require.NoError(t, err)
assert.NotNil(t, res.Error)

h1 := jsonrpc.HandlerFunc(func(c context.Context, params *json.RawMessage) (any, *jsonrpc.Error) {
h1 := jsonrpc.HandlerFunc(func(_ context.Context, _ *json.RawMessage) (any, *jsonrpc.Error) {
return "hello", nil
})
require.NoError(t, mr.RegisterMethod("hello", h1, nil, nil))
h2 := jsonrpc.HandlerFunc(func(c context.Context, params *json.RawMessage) (any, *jsonrpc.Error) {
h2 := jsonrpc.HandlerFunc(func(_ context.Context, _ *json.RawMessage) (any, *jsonrpc.Error) {
return nil, jsonrpc.ErrInternal()
})
require.NoError(t, mr.RegisterMethod("bye", h2, nil, nil))

rec = httptest.NewRecorder()
r, err = http.NewRequestWithContext(context.Background(), "", "", bytes.NewReader([]byte(`{"jsonrpc":"2.0","id":"test","method":"hello","params":{}}`)))
r, err = http.NewRequestWithContext(t.Context(), "", "", bytes.NewReader([]byte(`{"jsonrpc":"2.0","id":"test","method":"hello","params":{}}`)))
require.NoError(t, err)
r.Header.Set("Content-Type", "application/json")

Expand All @@ -62,7 +62,7 @@ func TestHandler(t *testing.T) {
assert.Equal(t, "hello", res.Result)

rec = httptest.NewRecorder()
r, err = http.NewRequestWithContext(context.Background(), "", "", bytes.NewReader([]byte(`{"jsonrpc":"2.0","id":"test","method":"bye","params":{}}`)))
r, err = http.NewRequestWithContext(t.Context(), "", "", bytes.NewReader([]byte(`{"jsonrpc":"2.0","id":"test","method":"bye","params":{}}`)))
require.NoError(t, err)
r.Header.Set("Content-Type", "application/json")

Expand Down
21 changes: 10 additions & 11 deletions jsonrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package jsonrpc_test

import (
"bytes"
"context"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -16,7 +15,7 @@ import (
func TestParseRequest(t *testing.T) {
t.Parallel()

r, rerr := http.NewRequestWithContext(context.Background(), "", "", bytes.NewReader(nil))
r, rerr := http.NewRequestWithContext(t.Context(), "", "", bytes.NewReader(nil))
require.NoError(t, rerr)

_, _, err := jsonrpc.ParseRequest(r)
Expand All @@ -28,23 +27,23 @@ func TestParseRequest(t *testing.T) {
require.IsType(t, &jsonrpc.Error{}, err)
assert.Equal(t, jsonrpc.ErrorCodeInvalidRequest, err.Code)

r, rerr = http.NewRequestWithContext(context.Background(), "", "", bytes.NewReader([]byte("")))
r, rerr = http.NewRequestWithContext(t.Context(), "", "", bytes.NewReader([]byte("")))
require.NoError(t, rerr)

r.Header.Set("Content-Type", "application/json")
_, _, err = jsonrpc.ParseRequest(r)
require.IsType(t, &jsonrpc.Error{}, err)
assert.Equal(t, jsonrpc.ErrorCodeInvalidRequest, err.Code)

r, rerr = http.NewRequestWithContext(context.Background(), "", "", bytes.NewReader([]byte("test")))
r, rerr = http.NewRequestWithContext(t.Context(), "", "", bytes.NewReader([]byte("test")))
require.NoError(t, rerr)

r.Header.Set("Content-Type", "application/json")
_, _, err = jsonrpc.ParseRequest(r)
require.IsType(t, &jsonrpc.Error{}, err)
assert.Equal(t, jsonrpc.ErrorCodeParse, err.Code)

r, rerr = http.NewRequestWithContext(context.Background(), "", "", bytes.NewReader([]byte("{}")))
r, rerr = http.NewRequestWithContext(t.Context(), "", "", bytes.NewReader([]byte("{}")))
require.NoError(t, rerr)

r.Header.Set("Content-Type", "application/json")
Expand All @@ -53,23 +52,23 @@ func TestParseRequest(t *testing.T) {
require.NotEmpty(t, rs)
assert.False(t, batch)

r, rerr = http.NewRequestWithContext(context.Background(), "", "", bytes.NewReader([]byte("[")))
r, rerr = http.NewRequestWithContext(t.Context(), "", "", bytes.NewReader([]byte("[")))
require.NoError(t, rerr)

r.Header.Set("Content-Type", "application/json")
_, _, err = jsonrpc.ParseRequest(r)
require.IsType(t, &jsonrpc.Error{}, err)
assert.Equal(t, jsonrpc.ErrorCodeParse, err.Code)

r, rerr = http.NewRequestWithContext(context.Background(), "", "", bytes.NewReader([]byte("[test]")))
r, rerr = http.NewRequestWithContext(t.Context(), "", "", bytes.NewReader([]byte("[test]")))
require.NoError(t, rerr)

r.Header.Set("Content-Type", "application/json")
_, _, err = jsonrpc.ParseRequest(r)
require.IsType(t, &jsonrpc.Error{}, err)
assert.Equal(t, jsonrpc.ErrorCodeParse, err.Code)

r, rerr = http.NewRequestWithContext(context.Background(), "", "", bytes.NewReader([]byte("[{}]")))
r, rerr = http.NewRequestWithContext(t.Context(), "", "", bytes.NewReader([]byte("[{}]")))
require.NoError(t, rerr)

r.Header.Set("Content-Type", "application/json")
Expand Down Expand Up @@ -113,18 +112,18 @@ func TestSendResponse(t *testing.T) {
rec = httptest.NewRecorder()
err = jsonrpc.SendResponse(rec, []*jsonrpc.Response{r}, false)
require.NoError(t, err)
assert.Equal(t, `{"jsonrpc":"2.0","result":{"name":"john"},"id":"test"}
assert.JSONEq(t, `{"jsonrpc":"2.0","result":{"name":"john"},"id":"test"}
`, rec.Body.String())

rec = httptest.NewRecorder()
err = jsonrpc.SendResponse(rec, []*jsonrpc.Response{r}, true)
require.NoError(t, err)
assert.Equal(t, `[{"jsonrpc":"2.0","result":{"name":"john"},"id":"test"}]
assert.JSONEq(t, `[{"jsonrpc":"2.0","result":{"name":"john"},"id":"test"}]
`, rec.Body.String())

rec = httptest.NewRecorder()
err = jsonrpc.SendResponse(rec, []*jsonrpc.Response{r, r}, false)
require.NoError(t, err)
assert.Equal(t, `[{"jsonrpc":"2.0","result":{"name":"john"},"id":"test"},{"jsonrpc":"2.0","result":{"name":"john"},"id":"test"}]
assert.JSONEq(t, `[{"jsonrpc":"2.0","result":{"name":"john"},"id":"test"},{"jsonrpc":"2.0","result":{"name":"john"},"id":"test"}]
`, rec.Body.String())
}
2 changes: 1 addition & 1 deletion method_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestMethods(t *testing.T) {
}

func SampleHandler() *jsonrpc.HandlerFunc {
h := jsonrpc.HandlerFunc(func(c context.Context, params *json.RawMessage) (any, *jsonrpc.Error) {
h := jsonrpc.HandlerFunc(func(_ context.Context, _ *json.RawMessage) (any, *jsonrpc.Error) {
return (any)(nil), nil
})

Expand Down
Loading