From 47a7a537631152bf401b18d57398294bd1f79d64 Mon Sep 17 00:00:00 2001 From: 9seconds Date: Mon, 21 Jun 2021 17:12:17 +0300 Subject: [PATCH 1/4] Makefile updates --- Makefile | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 4c5942a..e818b1d 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,13 @@ GOTOOL := env "GOBIN=$(GOBIN)" "PATH=$(ROOT_DIR)/.bin:$(PATH)" # ----------------------------------------------------------------------------- +.PHONY: vendor +vendor: go.mod go.sum + @go mod vendor + +.bin: + @mkdir -p "$(GOBIN)" || true + .PHONY: all all: build @@ -31,23 +38,29 @@ clean: lint: @$(GOTOOL) golangci-lint run +.PHONY: fmt +fmt: + @$(GOTOOL) gofumpt -w -s -extra "$(ROOT_DIR)" + .PHONY: doc doc: @$(GOTOOL) godoc -http 0.0.0.0:10000 .PHONY: install-tools -install-tools: install-tools-lint install-tools-godoc +install-tools: install-tools-lint install-tools-godoc install-tools-gofumpt .PHONY: install-tools-lint -install-tools-lint: - @mkdir -p "$(GOBIN)" || true && \ - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh \ +install-tools-lint: .bin + @curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh \ | bash -s -- -b "$(GOBIN)" "$(GOLANGCI_LINT_VERSION)" .PHONY: install-tools-godoc -install-tools-godoc: - @mkdir -p "$(GOBIN)" || true && \ - $(GOTOOL) go get -u golang.org/x/tools/cmd/godoc +install-tools-godoc: .bin + @$(GOTOOL) go get -u golang.org/x/tools/cmd/godoc + +.PHONY: install-tools-gofumpt +install-tools-gofumpt: .bin + @$(GOTOOL) go get -u mvdan.cc/gofumpt .PHONY: upgrade-deps upgrade-deps: From 0f71cd50d46c61d13f8e6b7aabfaeca5f85800ce Mon Sep 17 00:00:00 2001 From: 9seconds Date: Mon, 21 Jun 2021 17:31:05 +0300 Subject: [PATCH 2/4] Run gofumpt --- auth/ip_whitelist_auth_test.go | 4 ++-- conns/unhijack_test.go | 2 +- errors/error_test.go | 1 - events/event_stream_test.go | 2 +- headers/headers_test.go | 4 ++-- layers/layer_filter_subnets_test.go | 5 ++--- opts_test.go | 16 ++++++++-------- upgrades/init_test.go | 2 +- 8 files changed, 17 insertions(+), 19 deletions(-) diff --git a/auth/ip_whitelist_auth_test.go b/auth/ip_whitelist_auth_test.go index 5f4a22b..be2e705 100644 --- a/auth/ip_whitelist_auth_test.go +++ b/auth/ip_whitelist_auth_test.go @@ -30,8 +30,8 @@ func (suite *IPWhitelistAuthTestSuite) SetupTest() { _, netv6, _ := net.ParseCIDR("2001:db8:85a3:8d3:1319:8a2e:370:7348/64") suite.auth, _ = auth.NewIPWhitelist(map[string][]net.IPNet{ - "user1": []net.IPNet{*net127, *net192}, - "user2": []net.IPNet{*netv6}, + "user1": {*net127, *net192}, + "user2": {*netv6}, }) } diff --git a/conns/unhijack_test.go b/conns/unhijack_test.go index ff76c57..51a34ff 100644 --- a/conns/unhijack_test.go +++ b/conns/unhijack_test.go @@ -84,7 +84,7 @@ func (suite *UnhijackTestSuite) TestKeepOpened() { } func (suite *UnhijackTestSuite) TestClose() { - suite.raw.On("Close").Return(nil) + suite.raw.On("Close").Return(nil) conns.FixHijackHandler(func(net.Conn) bool { return true diff --git a/errors/error_test.go b/errors/error_test.go index 204d578..a04344e 100644 --- a/errors/error_test.go +++ b/errors/error_test.go @@ -47,7 +47,6 @@ const errorJSONSchema = ` var errorJSONValidator = func() *gojsonschema.Schema { loader := gojsonschema.NewStringLoader(errorJSONSchema) rv, err := gojsonschema.NewSchema(loader) - if err != nil { panic(err) } diff --git a/events/event_stream_test.go b/events/event_stream_test.go index 3149747..6337757 100644 --- a/events/event_stream_test.go +++ b/events/event_stream_test.go @@ -67,7 +67,7 @@ func (suite *EventStreamTestSuite) SetupTest() { suite.factory = &ProcessorMockFactory{ All: []*ProcessorMock{}, } - suite.stream = events.NewStream(ctx, suite.factory.Make) + suite.stream = events.NewStream(ctx, suite.factory.Make) sleep() } diff --git a/headers/headers_test.go b/headers/headers_test.go index 66b2c73..60a363c 100644 --- a/headers/headers_test.go +++ b/headers/headers_test.go @@ -29,8 +29,8 @@ func (suite *HeadersTestSuite) SetupTest() { suite.NoError(wrapper.Read(strings.NewReader(req))) - suite.hdrs.Reset(wrapper) - suite.NoError(suite.hdrs.Pull()) + suite.hdrs.Reset(wrapper) + suite.NoError(suite.hdrs.Pull()) } func (suite *HeadersTestSuite) TearDownTest() { diff --git a/layers/layer_filter_subnets_test.go b/layers/layer_filter_subnets_test.go index d1b8571..e79aa90 100644 --- a/layers/layer_filter_subnets_test.go +++ b/layers/layer_filter_subnets_test.go @@ -14,18 +14,17 @@ type FilterSubnetLayerTestSuite struct { func (suite *FilterSubnetLayerTestSuite) SetupTest() { suite.BaseLayerTestSuite.SetupTest() - } func (suite *FilterSubnetLayerTestSuite) TestIPv4() { suite.l, _ = layers.NewFilterSubnetsLayer([]net.IPNet{ - net.IPNet{IP: net.ParseIP("127.0.0.1"), Mask: net.CIDRMask(24, 32)}, + {IP: net.ParseIP("127.0.0.1"), Mask: net.CIDRMask(24, 32)}, }) suite.Error(suite.l.OnRequest(suite.ctx)) suite.l, _ = layers.NewFilterSubnetsLayer([]net.IPNet{ - net.IPNet{IP: net.ParseIP("10.0.0.10"), Mask: net.CIDRMask(24, 32)}, + {IP: net.ParseIP("10.0.0.10"), Mask: net.CIDRMask(24, 32)}, }) suite.NoError(suite.l.OnRequest(suite.ctx)) diff --git a/opts_test.go b/opts_test.go index 6704913..b4d6da4 100644 --- a/opts_test.go +++ b/opts_test.go @@ -131,28 +131,28 @@ func (suite *OptsTestSuite) TestGetTLSSkipVerify() { func (suite *OptsTestSuite) TestGetLayers() { suite.Len(suite.o.GetLayers(), 2) - lr := layers.TimeoutLayer{Timeout: time.Second} + lr := layers.TimeoutLayer{Timeout: time.Second} suite.o.Layers = []layers.Layer{lr} suite.Len(suite.o.GetLayers(), 3) - suite.Equal(lr, suite.o.GetLayers()[1]) + suite.Equal(lr, suite.o.GetLayers()[1]) } func (suite *OptsTestSuite) TestGetAuthenticator() { - suite.IsType(auth.NoopAuth{}, suite.o.GetAuthenticator()) + suite.IsType(auth.NoopAuth{}, suite.o.GetAuthenticator()) - suite.o.Authenticator = auth.NewBasicAuth(nil) + suite.o.Authenticator = auth.NewBasicAuth(nil) - suite.Equal(suite.o.Authenticator, suite.o.GetAuthenticator()) + suite.Equal(suite.o.Authenticator, suite.o.GetAuthenticator()) } func (suite *OptsTestSuite) TestGetExecutor() { - suite.Nil(suite.o.GetExecutor()) + suite.Nil(suite.o.GetExecutor()) - suite.o.Executor = func(_ *layers.Context) error { return nil } + suite.o.Executor = func(_ *layers.Context) error { return nil } - suite.NotNil(suite.o.GetExecutor()) + suite.NotNil(suite.o.GetExecutor()) } func TestOpts(t *testing.T) { diff --git a/upgrades/init_test.go b/upgrades/init_test.go index 5d9f599..ffd32b7 100644 --- a/upgrades/init_test.go +++ b/upgrades/init_test.go @@ -54,7 +54,7 @@ func (m *MockConn) SetWriteDeadline(tm time.Time) error { } type UpgradesTestSuite struct { - suite.Suite + suite.Suite up upgrades.Interface clientConn *MockConn From 52213e88828181f62c2ae5703c366b6b135aad9e Mon Sep 17 00:00:00 2001 From: 9seconds Date: Mon, 21 Jun 2021 17:35:13 +0300 Subject: [PATCH 3/4] Update golangci-lint --- .github/workflows/ci.yaml | 2 +- Makefile | 2 +- auth/ip_whitelist_auth.go | 4 ++-- ca/worker.go | 18 ++++++++++-------- cache/cache.go | 2 +- conns/unread_conn.go | 2 +- dialers/http_proxy.go | 2 +- dialers/socks5.go | 4 ++-- dialers/std_dialer_wrapper.go | 2 +- dns/dns.go | 4 ++-- errors/error_json.go | 2 +- headers/bufio_reader_pool.go | 2 +- headers/bytes_reader_pool.go | 2 +- http/buffered_reader.go | 2 +- layers/ctx.go | 2 +- layers/layer_filter_subnets.go | 10 ++++------ server.go | 8 ++++---- upgrades/tcp.go | 4 ++-- upgrades/websockets.go | 4 ++-- 19 files changed, 39 insertions(+), 39 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 803e2a5..7f0d55b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -64,4 +64,4 @@ jobs: - name: Run linter uses: golangci/golangci-lint-action@v2 with: - version: v1.37.1 + version: v1.41.1 diff --git a/Makefile b/Makefile index e818b1d..a1a3596 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) -GOLANGCI_LINT_VERSION := v1.37.1 +GOLANGCI_LINT_VERSION := v1.41.1 GOBIN := $(ROOT_DIR)/.bin GOTOOL := env "GOBIN=$(GOBIN)" "PATH=$(ROOT_DIR)/.bin:$(PATH)" diff --git a/auth/ip_whitelist_auth.go b/auth/ip_whitelist_auth.go index c6be59a..45d1530 100644 --- a/auth/ip_whitelist_auth.go +++ b/auth/ip_whitelist_auth.go @@ -18,7 +18,7 @@ func (i *ipWhitelist) Authenticate(ctx *fasthttp.RequestCtx) (string, error) { ip := ctx.RemoteIP() if ip4 := ip.To4(); ip4 != nil { - addr := patricia.NewIPv4AddressFromBytes(ip4, 32) + addr := patricia.NewIPv4AddressFromBytes(ip4, 32) // nolint: gomnd if ok, user, err := i.v4.FindDeepestTag(addr); ok && err == nil { return user, nil @@ -27,7 +27,7 @@ func (i *ipWhitelist) Authenticate(ctx *fasthttp.RequestCtx) (string, error) { return "", ErrFailedAuth } - addr := patricia.NewIPv6Address(ip, 128) + addr := patricia.NewIPv6Address(ip, 128) // nolint: gomnd if ok, user, err := i.v6.FindDeepestTag(addr); ok && err == nil { return user, nil diff --git a/ca/worker.go b/ca/worker.go index 0ddb62a..43d8d47 100644 --- a/ca/worker.go +++ b/ca/worker.go @@ -61,7 +61,7 @@ func (w *worker) Run() { var conf *tls.Config if cert := w.cache.Get(req.host); cert != nil { - conf = cert.(*tls.Config) + conf, _ = cert.(*tls.Config) } else { conf = w.process(req.host) w.cache.Add(req.host, conf) @@ -79,11 +79,13 @@ func (w *worker) process(host string) *tls.Config { now := time.Now() template := x509.Certificate{ - SerialNumber: &big.Int{}, - Issuer: w.ca.Leaf.Subject, - Subject: pkix.Name{}, - NotBefore: now.AddDate(0, 0, -1), // 1 day before - NotAfter: now.AddDate(0, 3, 0), // 3 months after + SerialNumber: &big.Int{}, + Issuer: w.ca.Leaf.Subject, + Subject: pkix.Name{}, + // 1 day before + NotBefore: now.AddDate(0, 0, -1), + // 3 months after + NotAfter: now.AddDate(0, 3, 0), // nolint: gomnd KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, BasicConstraintsValid: true, @@ -96,8 +98,8 @@ func (w *worker) process(host string) *tls.Config { template.Subject.CommonName = host } - randBytes := make([]byte, 64) - rand.Read(randBytes) // nolint: errcheck + randBytes := make([]byte, 64) // nolint: gomnd + rand.Read(randBytes) // nolint: errcheck template.SerialNumber.SetBytes(randBytes) certPriv, err := rsa.GenerateKey(rand.Reader, RSAKeyLength) diff --git a/cache/cache.go b/cache/cache.go index f9c8fd1..c5fd98a 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -44,7 +44,7 @@ func New(size int, ttl time.Duration, callback EvictCallback) Interface { BufferItems: 64, // nolint: gomnd Metrics: false, OnEvict: func(_, _ uint64, value interface{}, _ int64) { - vv := value.(*cacheItem) + vv, _ := value.(*cacheItem) callback(vv.key, vv.value) }, } diff --git a/conns/unread_conn.go b/conns/unread_conn.go index d10d6aa..462d15a 100644 --- a/conns/unread_conn.go +++ b/conns/unread_conn.go @@ -32,7 +32,7 @@ func (u *UnreadConn) Read(p []byte) (int, error) { u.mutex.RLock() defer u.mutex.RUnlock() - return u.reader.Read(p) + return u.reader.Read(p) // nolint: wrapcheck } // Unread transitions UnreadConn into 'unreading' state. diff --git a/dialers/http_proxy.go b/dialers/http_proxy.go index aee6073..8f5e396 100644 --- a/dialers/http_proxy.go +++ b/dialers/http_proxy.go @@ -95,7 +95,7 @@ func (h *httpProxy) PatchHTTPRequest(req *fasthttp.Request) { } func (h *httpProxy) acquireBufioReader(rd io.Reader) *bufio.Reader { - rv := h.bufioReaderPool.Get().(*bufio.Reader) + rv, _ := h.bufioReaderPool.Get().(*bufio.Reader) rv.Reset(rd) diff --git a/dialers/socks5.go b/dialers/socks5.go index 4694f3b..784f95e 100644 --- a/dialers/socks5.go +++ b/dialers/socks5.go @@ -15,7 +15,7 @@ type socksProxy struct { } func (s *socksProxy) Dial(ctx context.Context, host, port string) (net.Conn, error) { - return s.proxy.DialContext(ctx, "tcp", net.JoinHostPort(host, port)) + return s.proxy.DialContext(ctx, "tcp", net.JoinHostPort(host, port)) // nolint: wrapcheck } func (s *socksProxy) UpgradeToTLS(ctx context.Context, conn net.Conn, host, port string) (net.Conn, error) { @@ -29,7 +29,7 @@ func (s *socksProxy) PatchHTTPRequest(req *fasthttp.Request) { // NewSocks5 returns a dialer which can connect to SOCKS5 proxies. It // uses a base dialer under the hood. func NewSocks5(opt Opts, proxyAuth ProxyAuth) (Dialer, error) { - baseDialer := NewBase(opt).(*base) + baseDialer, _ := NewBase(opt).(*base) var auth *proxy.Auth diff --git a/dialers/std_dialer_wrapper.go b/dialers/std_dialer_wrapper.go index 6c880e2..39f9057 100644 --- a/dialers/std_dialer_wrapper.go +++ b/dialers/std_dialer_wrapper.go @@ -25,7 +25,7 @@ func (s StdDialerWrapper) DialContext(ctx context.Context, network, address stri return nil, fmt.Errorf("incorrect address: %w", err) } - return s.Dialer.Dial(ctx, host, port) + return s.Dialer.Dial(ctx, host, port) // nolint: wrapcheck } // Dial is to conform Dial method of net.Dialer. diff --git a/dns/dns.go b/dns/dns.go index 6af8690..a58379b 100644 --- a/dns/dns.go +++ b/dns/dns.go @@ -19,7 +19,7 @@ type DNS struct { // Lookup to conform Interface. func (d *DNS) Lookup(ctx context.Context, hostname string) (hosts []string, err error) { if hh := d.cache.Get(hostname); hh != nil { - hosts = hh.([]string) + hosts, _ = hh.([]string) } else { hosts, err = d.doLookup(ctx, hostname) @@ -35,7 +35,7 @@ func (d *DNS) Lookup(ctx context.Context, hostname string) (hosts []string, err func (d *DNS) doLookup(ctx context.Context, hostname string) ([]string, error) { if net.ParseIP(hostname) == nil { - return d.resolver.LookupHost(ctx, hostname) + return d.resolver.LookupHost(ctx, hostname) // nolint: wrapcheck } addrs, err := d.resolver.LookupIPAddr(ctx, hostname) diff --git a/errors/error_json.go b/errors/error_json.go index 7051cba..89cb063 100644 --- a/errors/error_json.go +++ b/errors/error_json.go @@ -16,7 +16,7 @@ type errorJSON struct { type errorJSONStackEntry struct { Code string `json:"code"` Message string `json:"message"` - StatusCode int `json:"status_code"` + StatusCode int `json:"status_code"` // nolint: tagliatelle } func writeErrorAsJSON(err *Error, writer io.Writer) { diff --git a/headers/bufio_reader_pool.go b/headers/bufio_reader_pool.go index e0d80a5..9798c42 100644 --- a/headers/bufio_reader_pool.go +++ b/headers/bufio_reader_pool.go @@ -15,7 +15,7 @@ var poolBufioReader = sync.Pool{ } func acquireBufioReader(rd io.Reader) *bufio.Reader { - reader := poolBufioReader.Get().(*bufio.Reader) + reader, _ := poolBufioReader.Get().(*bufio.Reader) reader.Reset(rd) diff --git a/headers/bytes_reader_pool.go b/headers/bytes_reader_pool.go index 0f68594..d42c8e3 100644 --- a/headers/bytes_reader_pool.go +++ b/headers/bytes_reader_pool.go @@ -12,7 +12,7 @@ var poolBytesReader = sync.Pool{ } func acquireBytesReader(data []byte) *bytes.Reader { - rd := poolBytesReader.Get().(*bytes.Reader) + rd, _ := poolBytesReader.Get().(*bytes.Reader) rd.Reset(data) diff --git a/http/buffered_reader.go b/http/buffered_reader.go index a7aa8d8..9357bed 100644 --- a/http/buffered_reader.go +++ b/http/buffered_reader.go @@ -19,7 +19,7 @@ var poolBufioReader = sync.Pool{ } func acquireBufioReader(rd io.Reader) *bufio.Reader { - reader := poolBufioReader.Get().(*bufio.Reader) + reader, _ := poolBufioReader.Get().(*bufio.Reader) reader.Reset(rd) diff --git a/layers/ctx.go b/layers/ctx.go index 59d14d8..32c3570 100644 --- a/layers/ctx.go +++ b/layers/ctx.go @@ -260,7 +260,7 @@ func (c *Context) Done() <-chan struct{} { // Err conforms a context.Context interface. func (c *Context) Err() error { - return c.ctx.Err() + return c.ctx.Err() // nolint: wrapcheck } // Value conforms a context.Context interface. diff --git a/layers/layer_filter_subnets.go b/layers/layer_filter_subnets.go index 1cec82e..900ff45 100644 --- a/layers/layer_filter_subnets.go +++ b/layers/layer_filter_subnets.go @@ -22,7 +22,7 @@ func (f *filterSubnetsLayer) OnRequest(ctx *Context) error { resolved, err := dns.Default.Lookup(ctx, host) if err != nil { // pass unresolved name, delegate it to executor. - return nil + return nil // nolint: nilerr } for _, v := range resolved { @@ -39,9 +39,7 @@ func (f *filterSubnetsLayer) OnRequest(ctx *Context) error { } func (f *filterSubnetsLayer) filterIP(ip net.IP) bool { - ip4 := ip.To4() - - if ip4 != nil { + if ip4 := ip.To4(); ip4 != nil { return f.filterIPv4(ip4) } @@ -49,7 +47,7 @@ func (f *filterSubnetsLayer) filterIP(ip net.IP) bool { } func (f *filterSubnetsLayer) filterIPv4(addr net.IP) bool { - ip := patricia.NewIPv4AddressFromBytes(addr, 32) + ip := patricia.NewIPv4AddressFromBytes(addr, 32) // nolint: gomnd if ok, _, err := f.v4.FindDeepestTag(ip); ok && err == nil { return true @@ -59,7 +57,7 @@ func (f *filterSubnetsLayer) filterIPv4(addr net.IP) bool { } func (f *filterSubnetsLayer) filterIPv6(addr net.IP) bool { - ip := patricia.NewIPv6Address(addr, 128) + ip := patricia.NewIPv6Address(addr, 128) // nolint: gomnd if ok, _, err := f.v6.FindDeepestTag(ip); ok && err == nil { return true diff --git a/server.go b/server.go index c9ba889..a204d43 100644 --- a/server.go +++ b/server.go @@ -38,14 +38,14 @@ type Server struct { // Serve starts to serve on given net.Listener instance. func (s *Server) Serve(ln net.Listener) error { - return s.server.Serve(ln) + return s.server.Serve(ln) // nolint: wrapcheck } // Close stops server. func (s *Server) Close() error { s.ctxCancel() - return s.server.Shutdown() + return s.server.Shutdown() // nolint: wrapcheck } func (s *Server) entrypoint(ctx *fasthttp.RequestCtx) { @@ -134,7 +134,7 @@ func (s *Server) upgradeToTLS(requestType events.RequestType, user, address stri uConn.Seal() } - srv := s.serverPool.Get().(*fasthttp.Server) + srv, _ := s.serverPool.Get().(*fasthttp.Server) defer s.serverPool.Put(srv) needToClose := true @@ -318,7 +318,7 @@ func NewServer(ctx context.Context, opts ServerOpts) (*Server, error) { // nolin }, }, } - srv.server = srv.serverPool.Get().(*fasthttp.Server) + srv.server, _ = srv.serverPool.Get().(*fasthttp.Server) srv.server.Handler = srv.entrypoint go func() { diff --git a/upgrades/tcp.go b/upgrades/tcp.go index cb70639..c1c5b15 100644 --- a/upgrades/tcp.go +++ b/upgrades/tcp.go @@ -113,7 +113,7 @@ var poolTCP = sync.Pool{ // AcquireTCP returns a new TCP upgrader from the pool. func AcquireTCP(reactor TCPReactor) Interface { - rv := poolTCP.Get().(*tcpInterface) + rv, _ := poolTCP.Get().(*tcpInterface) rv.reactor = reactor @@ -122,7 +122,7 @@ func AcquireTCP(reactor TCPReactor) Interface { // ReleaseTCP returns TCP upgrader back to the object pool. func ReleaseTCP(up Interface) { - value := up.(*tcpInterface) + value, _ := up.(*tcpInterface) value.reactor = nil poolTCP.Put(value) diff --git a/upgrades/websockets.go b/upgrades/websockets.go index de596d5..cda0821 100644 --- a/upgrades/websockets.go +++ b/upgrades/websockets.go @@ -124,7 +124,7 @@ var poolWebsocket = sync.Pool{ // AcquireWebsocket returns a new Websocket upgrader from the pool. func AcquireWebsocket(reactor WebsocketReactor) Interface { - rv := poolWebsocket.Get().(*websocketInterface) + rv, _ := poolWebsocket.Get().(*websocketInterface) rv.reactor = reactor @@ -133,7 +133,7 @@ func AcquireWebsocket(reactor WebsocketReactor) Interface { // ReleaseWebsocket returns Websocket back to the object pool. func ReleaseWebsocket(up Interface) { - value := up.(*websocketInterface) + value, _ := up.(*websocketInterface) value.reactor = nil poolWebsocket.Put(value) From 1330e48e6002e4cfb3b6a9409552a36ddc4fbb1d Mon Sep 17 00:00:00 2001 From: 9seconds Date: Mon, 21 Jun 2021 17:56:55 +0300 Subject: [PATCH 4/4] Update dependencies --- cache/cache.go | 10 ++++----- go.mod | 13 ++++++------ go.sum | 56 ++++++++++++++++++++++++++------------------------ 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index c5fd98a..c81b938 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -6,7 +6,6 @@ import ( "github.com/dgraph-io/ristretto" ) -// please remove it when ristretto >0.0.3 will be released. type cacheItem struct { key string value interface{} @@ -41,10 +40,11 @@ func New(size int, ttl time.Duration, callback EvictCallback) Interface { NumCounters: int64(10 * size), // nolint: gomnd MaxCost: int64(size), // 64 is also taken from official documentation. - BufferItems: 64, // nolint: gomnd - Metrics: false, - OnEvict: func(_, _ uint64, value interface{}, _ int64) { - vv, _ := value.(*cacheItem) + BufferItems: 64, // nolint: gomnd + Metrics: false, + IgnoreInternalCost: true, + OnEvict: func(item *ristretto.Item) { + vv, _ := item.Value.(*cacheItem) callback(vv.key, vv.value) }, } diff --git a/go.mod b/go.mod index 62119a0..6f6e952 100644 --- a/go.mod +++ b/go.mod @@ -2,25 +2,26 @@ module github.com/9seconds/httransform/v2 require ( github.com/OneOfOne/xxhash v1.2.8 - github.com/andybalholm/brotli v1.0.1 // indirect + github.com/andybalholm/brotli v1.0.3 // indirect github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 - github.com/dgraph-io/ristretto v0.0.3 + github.com/dgraph-io/ristretto v0.1.0 github.com/go-httpproxy/httpproxy v0.0.0-20180417134941-6977c68bf38e github.com/gobwas/httphead v0.1.0 // indirect github.com/gobwas/pool v0.2.1 // indirect github.com/gobwas/ws v1.0.4 github.com/gofrs/uuid v4.0.0+incompatible + github.com/golang/glog v0.0.0-20210429001901-424d2337a529 // indirect github.com/gorilla/websocket v1.4.2 github.com/kentik/patricia v0.0.0-20201202224819-f9447a6e25f1 - github.com/klauspost/compress v1.11.7 // indirect + github.com/klauspost/compress v1.13.1 // indirect github.com/libp2p/go-reuseport v0.0.2 github.com/mccutchen/go-httpbin v1.1.1 github.com/stretchr/testify v1.5.1 - github.com/valyala/fasthttp v1.21.0 + github.com/valyala/fasthttp v1.27.0 github.com/valyala/fastrand v1.0.0 github.com/xeipuuv/gojsonschema v1.2.0 - golang.org/x/net v0.0.0-20210224082022-3d97a244fca7 - golang.org/x/sys v0.0.0-20210223212115-eede4237b368 // indirect + golang.org/x/net v0.0.0-20210614182718-04defd469f4e + golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 // indirect ) go 1.15 diff --git a/go.sum b/go.sum index 20de880..8fa4f00 100644 --- a/go.sum +++ b/go.sum @@ -1,20 +1,21 @@ -github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/OneOfOne/xxhash v1.2.8 h1:31czK/TI9sNkxIKfaUfGlU47BAxQ0ztGgd9vPyqimf8= github.com/OneOfOne/xxhash v1.2.8/go.mod h1:eZbhyaAYD41SGSSsnmcpxVoRiQ/MPUTjUdIIOT9Um7Q= -github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= -github.com/andybalholm/brotli v1.0.1 h1:KqhlKozYbRtJvsPrrEeXcO+N2l6NYT5A2QAFmSULpEc= -github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= +github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= +github.com/andybalholm/brotli v1.0.3 h1:fpcw+r1N1h0Poc1F/pHbW40cUm/lMEQslZtCkBQ0UnM= +github.com/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= -github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= +github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= +github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 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/dgraph-io/ristretto v0.0.3 h1:jh22xisGBjrEVnRZ1DVTpBVQm0Xndu8sMl0CWDzSIBI= -github.com/dgraph-io/ristretto v0.0.3/go.mod h1:KPxhHT9ZxKefz+PCeOGsrHpl1qZ7i70dGTu2u+Ahh6E= +github.com/dgraph-io/ristretto v0.1.0 h1:Jv3CGQHp9OjuMBSne1485aDpUkTKEcUqF+jm/LuerPI= +github.com/dgraph-io/ristretto v0.1.0/go.mod h1:fux0lOrBhrVCJd3lcTHsIJhq1T2rokOu6v9Vcb3Q9ug= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2 h1:tdlZCpZ/P9DhczCTSixgIKmwPv6+wP5DGjqLYw5SUiA= github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw= +github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo= +github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/go-httpproxy/httpproxy v0.0.0-20180417134941-6977c68bf38e h1:ZWrG9Qs9xKF9638OVBT9Dd84CduxRWKX1/ZuwDI9e5o= github.com/go-httpproxy/httpproxy v0.0.0-20180417134941-6977c68bf38e/go.mod h1:Ftx0ecWwj8tX+5XPIE2KldKlneCsk9xMEaVpNbFRSt4= github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU= @@ -25,13 +26,17 @@ github.com/gobwas/ws v1.0.4 h1:5eXU1CZhpQdq5kXbKb+sECH5Ia5KiO6CYzIzdlVx6Bs= github.com/gobwas/ws v1.0.4/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/glog v0.0.0-20210429001901-424d2337a529 h1:2voWjNECnrZRbfwXxHB1/j8wa6xdKn85B5NzgVL/pTU= +github.com/golang/glog v0.0.0-20210429001901-424d2337a529/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/kentik/patricia v0.0.0-20201202224819-f9447a6e25f1 h1:D7qhJP3R49ZjUzpzKQ6B2H3lgejPs6DTO5gRomhhOpE= github.com/kentik/patricia v0.0.0-20201202224819-f9447a6e25f1/go.mod h1:2OfLA+0esiUJpwMjrH39pEk79cb8MvGTBS9YlZpejJ4= -github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= -github.com/klauspost/compress v1.11.7 h1:0hzRabrMN4tSTvMfnL3SCv1ZGeAP23ynzodBgaHeMeg= -github.com/klauspost/compress v1.11.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/klauspost/compress v1.12.2/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= +github.com/klauspost/compress v1.13.1 h1:wXr2uRxZTJXHLly6qhJabee5JqIhTRoLBhDOA74hDEQ= +github.com/klauspost/compress v1.13.1/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= github.com/libp2p/go-reuseport v0.0.2 h1:XSG94b1FJfGA01BUrT82imejHQyTxO4jEWqheyCXYvU= github.com/libp2p/go-reuseport v0.0.2/go.mod h1:SPD+5RwGC7rcnzngoYC86GjPzjSywuQyMVAheVBD9nQ= github.com/mccutchen/go-httpbin v1.1.1 h1:aEws49HEJEyXHLDnshQVswfUlCVoS8g6h9YaDyaW7RE= @@ -40,8 +45,6 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ= -github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.1.5-0.20170809224252-890a5c3458b4/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= @@ -51,33 +54,32 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.21.0 h1:fJjaQ7cXdaSF9vDBujlHLDGj7AgoMTMIXvICeePzYbU= -github.com/valyala/fasthttp v1.21.0/go.mod h1:jjraHZVbKOXftJfsOYoAjaeygpj5hr8ermTRJNroD7A= +github.com/valyala/fasthttp v1.27.0 h1:gDefRDL9aqSiwXV6aRW8aSBPs82y4KizSzHrBLf4NDI= +github.com/valyala/fasthttp v1.27.0/go.mod h1:cmWIqlu99AO/RKcp1HWaViTqc57FswJOfYYdPJBl8BA= github.com/valyala/fastrand v1.0.0 h1:LUKT9aKer2dVQNUi3waewTbKV+7H17kvWFNKs2ObdkI= github.com/valyala/fastrand v1.0.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ= -github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= +github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c= github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0= github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20201016165138-7b1cca2348c0/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210224082022-3d97a244fca7 h1:OgUuv8lsRpBibGNbSizVwKWlysjaNzmC9gYMhPVfqFM= -golang.org/x/net v0.0.0-20210224082022-3d97a244fca7/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q= +golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sys v0.0.0-20190228124157-a34e9553db1e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210223212115-eede4237b368 h1:fDE3p0qf2V1co1vfj3/o87Ps8Hq6QTGNxJ5Xe7xSp80= -golang.org/x/sys v0.0.0-20210223212115-eede4237b368/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22 h1:RqytpXGR1iVNX7psjB3ff8y7sNFinVFvkx1c8SjBkio= +golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 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=