From 6bb5c90a1e368108a00f01c255df04de201960b5 Mon Sep 17 00:00:00 2001 From: Dmitry Verkhoturov Date: Tue, 19 Jul 2022 22:03:07 +0200 Subject: [PATCH] bump didip/tollbooth from v6 to v7, get rid of error module tollbooth started emitting new rate-limiting headers in v7, and pkg/errors are deprecated in favour of the new stdlib. --- .github/workflows/ci.yml | 2 +- client.go | 19 +++++++++---------- go.mod | 14 +++++++------- go.sum | 35 ++++++++++++++++------------------- server.go | 9 ++++----- server_test.go | 4 ++-- 6 files changed, 39 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 19c0128..887babb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: - name: install golangci-lint and goveralls run: | - curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $GITHUB_WORKSPACE v1.43.0 + curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh| sh -s -- -b $GITHUB_WORKSPACE v1.46.2 GO111MODULE=off go get -u -v github.com/mattn/goveralls - name: run linters diff --git a/client.go b/client.go index b9a4057..0a51630 100644 --- a/client.go +++ b/client.go @@ -3,10 +3,9 @@ package jrpc import ( "bytes" "encoding/json" + "fmt" "net/http" "sync/atomic" - - "github.com/pkg/errors" ) // Client implements remote engine and delegates all calls to remote http server @@ -33,23 +32,23 @@ func (r *Client) Call(method string, args ...interface{}) (*Response, error) { case len(args) == 0: b, err = json.Marshal(Request{Method: method, ID: atomic.AddUint64(&r.id, 1)}) if err != nil { - return nil, errors.Wrapf(err, "marshaling failed for %s", method) + return nil, fmt.Errorf("marshaling failed for %s: %w", method, err) } case len(args) == 1: b, err = json.Marshal(Request{Method: method, Params: args[0], ID: atomic.AddUint64(&r.id, 1)}) if err != nil { - return nil, errors.Wrapf(err, "marshaling failed for %s", method) + return nil, fmt.Errorf("marshaling failed for %s: %w", method, err) } default: b, err = json.Marshal(Request{Method: method, Params: args, ID: atomic.AddUint64(&r.id, 1)}) if err != nil { - return nil, errors.Wrapf(err, "marshaling failed for %s", method) + return nil, fmt.Errorf("marshaling failed for %s: %w", method, err) } } req, err := http.NewRequest("POST", r.API, bytes.NewBuffer(b)) if err != nil { - return nil, errors.Wrapf(err, "failed to make request for %s", method) + return nil, fmt.Errorf("failed to make request for %s: %w", method, err) } req.Header.Set("Content-Type", "application/json; charset=utf-8") @@ -58,20 +57,20 @@ func (r *Client) Call(method string, args ...interface{}) (*Response, error) { } resp, err := r.Client.Do(req) if err != nil { - return nil, errors.Wrapf(err, "remote call failed for %s", method) + return nil, fmt.Errorf("remote call failed for %s: %w", method, err) } defer resp.Body.Close() if resp.StatusCode != 200 { - return nil, errors.Errorf("bad status %s for %s", resp.Status, method) + return nil, fmt.Errorf("bad status %s for %s", resp.Status, method) } cr := Response{} if err = json.NewDecoder(resp.Body).Decode(&cr); err != nil { - return nil, errors.Wrapf(err, "failed to decode response for %s", method) + return nil, fmt.Errorf("failed to decode response for %s: %w", method, err) } if cr.Error != "" { - return nil, errors.New(cr.Error) + return nil, fmt.Errorf("%s", cr.Error) } return &cr, nil } diff --git a/go.mod b/go.mod index 8f34266..24cf376 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,12 @@ module github.com/go-pkgz/jrpc go 1.16 require ( - github.com/didip/tollbooth/v6 v6.1.0 - github.com/didip/tollbooth_chi v0.0.0-20200828173446-a7173453ea21 - github.com/go-chi/chi/v5 v5.0.0 + github.com/didip/tollbooth/v7 v7.0.0 + github.com/didip/tollbooth_chi v0.0.0-20220719025231-d662a7f6928f + github.com/go-chi/chi/v5 v5.0.7 github.com/go-chi/render v1.0.1 - github.com/go-pkgz/rest v1.5.0 - github.com/pkg/errors v0.9.1 - github.com/stretchr/testify v1.7.0 - golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 // indirect + github.com/go-pkgz/rest v1.15.6 + github.com/kr/pretty v0.1.0 // indirect + github.com/stretchr/testify v1.8.0 + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect ) diff --git a/go.sum b/go.sum index 0a06382..a9e08b9 100644 --- a/go.sum +++ b/go.sum @@ -1,19 +1,18 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 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/didip/tollbooth/v6 v6.0.1/go.mod h1:j2pKs+JQ5PvU/K4jFnrnwntrmfUbYLJE5oSdxR37FD0= -github.com/didip/tollbooth/v6 v6.1.0 h1:ZS2fNa9JhFdRSJCj3+V12VfuUifYrGB4Z0jSwXmKMeE= -github.com/didip/tollbooth/v6 v6.1.0/go.mod h1:xjcse6CTHCLuOkzsWrEgdy9WPJFv+p/x6v+MyfP+O9s= -github.com/didip/tollbooth_chi v0.0.0-20200828173446-a7173453ea21 h1:x7YpwKSBIBcKe9I3aTNOqgSyJ6QKDdtOxnEkxBTsi9w= -github.com/didip/tollbooth_chi v0.0.0-20200828173446-a7173453ea21/go.mod h1:0ZVa6kSzS011nfTC1rELyxK4tjVf6vqBnOv7oY2KlsA= -github.com/go-chi/chi/v5 v5.0.0 h1:DBPx88FjZJH3FsICfDAfIfnb7XxKIYVGG6lOPlhENAg= -github.com/go-chi/chi/v5 v5.0.0/go.mod h1:BBug9lr0cqtdAhsu6R4AAdvufI0/XBzAQSsUqJpoZOs= +github.com/didip/tollbooth/v7 v7.0.0 h1:XmyyNwZpz9j61PwR4A894MmmYO5zBF9xjgVi2n1fiQI= +github.com/didip/tollbooth/v7 v7.0.0/go.mod h1:VZhDSGl5bDSPj4wPsih3PFa4Uh9Ghv8hgacaTm5PRT4= +github.com/didip/tollbooth_chi v0.0.0-20220719025231-d662a7f6928f h1:jtKwihcLmUC9BAhoJ9adCUqdSSZcOdH2KL7mPTUm2aw= +github.com/didip/tollbooth_chi v0.0.0-20220719025231-d662a7f6928f/go.mod h1:q9C80dnsuVRP2dAskjnXRNWdUJqtGgwG9wNrzt0019s= +github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8= +github.com/go-chi/chi/v5 v5.0.7/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= github.com/go-chi/render v1.0.1 h1:4/5tis2cKaNdnv9zFLfXzcquC9HbeZgCnxGnKrltBS8= github.com/go-chi/render v1.0.1/go.mod h1:pq4Rr7HbnsdaeHagklXub+p6Wd16Af5l9koip1OvJns= -github.com/go-pkgz/expirable-cache v0.0.3 h1:rTh6qNPp78z0bQE6HDhXBHUwqnV9i09Vm6dksJLXQDc= -github.com/go-pkgz/expirable-cache v0.0.3/go.mod h1:+IauqN00R2FqNRLCLA+X5YljQJrwB179PfiAoMPlTlQ= -github.com/go-pkgz/rest v1.5.0 h1:C8SxXcXza4GiUUAn/95iCkvoIrGbS30qpwK19iqlrWQ= -github.com/go-pkgz/rest v1.5.0/go.mod h1:nQaM3RhSTUAmbBZWY4hfe4buyeC9VckvhoCktiQXJxI= +github.com/go-pkgz/expirable-cache v0.1.0 h1:3bw0m8vlTK8qlwz5KXuygNBTkiKRTPrAGXU0Ej2AC1g= +github.com/go-pkgz/expirable-cache v0.1.0/go.mod h1:GTrEl0X+q0mPNqN6dtcQXksACnzCBQ5k/k1SwXJsZKs= +github.com/go-pkgz/rest v1.15.6 h1:8RgOuY/c00CD0el8KdmscOCgDH+ML0ZsK2qa1Rcxal4= +github.com/go-pkgz/rest v1.15.6/go.mod h1:KUWAqbDteYGS/CiXftomQsKjtEOifXsJ36Ka0skYbmk= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -24,16 +23,14 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE 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/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE= -golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= 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= diff --git a/server.go b/server.go index 1305d6f..78b4322 100644 --- a/server.go +++ b/server.go @@ -8,14 +8,13 @@ import ( "sync" "time" - "github.com/didip/tollbooth/v6" + "github.com/didip/tollbooth/v7" "github.com/didip/tollbooth_chi" "github.com/go-chi/chi/v5" "github.com/go-chi/chi/v5/middleware" "github.com/go-chi/render" "github.com/go-pkgz/rest" "github.com/go-pkgz/rest/logger" - "github.com/pkg/errors" ) // Server is json-rpc server with an optional basic auth @@ -94,7 +93,7 @@ func (s *Server) Run(port int) error { } if s.funcs.m == nil && len(s.funcs.m) == 0 { - return errors.Errorf("nothing mapped for dispatch, Add has to be called prior to Run") + return fmt.Errorf("nothing mapped for dispatch, Add has to be called prior to Run") } router := chi.NewRouter() @@ -144,7 +143,7 @@ func (s *Server) Shutdown() error { s.httpServer.Lock() defer s.httpServer.Unlock() if s.httpServer.Server == nil { - return errors.Errorf("http server is not running") + return fmt.Errorf("http server is not running") } ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() @@ -192,7 +191,7 @@ func (s *Server) handler(w http.ResponseWriter, r *http.Request) { } fn, ok := s.funcs.m[req.Method] if !ok { - rest.SendErrorJSON(w, r, s.logger, http.StatusNotImplemented, errors.New("unsupported method"), req.Method) + rest.SendErrorJSON(w, r, s.logger, http.StatusNotImplemented, fmt.Errorf("unsupported method"), req.Method) return } diff --git a/server_test.go b/server_test.go index 0dd25fb..0acb2f5 100644 --- a/server_test.go +++ b/server_test.go @@ -3,6 +3,7 @@ package jrpc import ( "bytes" "encoding/json" + "fmt" "io" "net/http" "net/http/httptest" @@ -10,7 +11,6 @@ import ( "testing" "time" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -176,7 +176,7 @@ func TestServerErrReturn(t *testing.T) { assert.Equal(t, 42., args[1].(float64)) assert.Equal(t, true, args[2].(bool)) - return EncodeResponse(id, "res blah", errors.New("some error")) + return EncodeResponse(id, "res blah", fmt.Errorf("some error")) }) go func() { _ = s.Run(9091) }()