From 5282ca26f3a714c9e56c58432367bbffc3043200 Mon Sep 17 00:00:00 2001 From: 9seconds Date: Fri, 11 Mar 2022 17:08:33 +0300 Subject: [PATCH] Update golangci-lint to 1.44.2 --- .github/workflows/ci.yaml | 2 +- .golangci.toml | 2 +- Makefile | 2 +- internal/testlib/mtglib_network_mock.go | 6 +++--- internal/testlib/net_conn_mock.go | 4 ++-- mtglib/internal/faketls/pools.go | 2 +- mtglib/internal/faketls/record/pools.go | 2 +- mtglib/internal/obfuscated2/pools.go | 4 ++-- mtglib/internal/obfuscated2/server_handshake_test.go | 4 ++-- mtglib/internal/relay/pools.go | 2 +- mtglib/proxy.go | 9 ++++++--- mtglib/stream_context.go | 2 +- network/default.go | 2 +- network/init_internal_test.go | 4 ++-- network/init_test.go | 4 ++-- network/sockopts.go | 4 ++-- stats/pools.go | 2 +- 17 files changed, 30 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 57c2e50..76dc7f8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -83,7 +83,7 @@ jobs: - name: Run linter uses: golangci/golangci-lint-action@v2 with: - version: v1.43.0 + version: v1.44.2 docker: name: Docker diff --git a/.golangci.toml b/.golangci.toml index 97f84a5..353b1d9 100644 --- a/.golangci.toml +++ b/.golangci.toml @@ -9,4 +9,4 @@ format = "colored-line-number" [linters] enable-all = true -disable = ["ireturn", "varnamelen", "gochecknoglobals", "gas", "goerr113", "exhaustivestruct"] +disable = ["ireturn", "varnamelen", "gochecknoglobals", "gas", "goerr113", "exhaustivestruct", "containedctx"] diff --git a/Makefile b/Makefile index c54a228..354cdec 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) IMAGE_NAME := mtg APP_NAME := $(IMAGE_NAME) -GOLANGCI_LINT_VERSION := v1.43.0 +GOLANGCI_LINT_VERSION := v1.44.2 VERSION_GO := $(shell go version) VERSION_DATE := $(shell date -Ru) diff --git a/internal/testlib/mtglib_network_mock.go b/internal/testlib/mtglib_network_mock.go index 97bd69a..a6d08bf 100644 --- a/internal/testlib/mtglib_network_mock.go +++ b/internal/testlib/mtglib_network_mock.go @@ -15,16 +15,16 @@ type MtglibNetworkMock struct { func (m *MtglibNetworkMock) Dial(network, address string) (essentials.Conn, error) { args := m.Called(network, address) - return args.Get(0).(essentials.Conn), args.Error(1) // nolint: wrapcheck + return args.Get(0).(essentials.Conn), args.Error(1) // nolint: wrapcheck, forcetypeassert } func (m *MtglibNetworkMock) DialContext(ctx context.Context, network, address string) (essentials.Conn, error) { args := m.Called(ctx, network, address) - return args.Get(0).(essentials.Conn), args.Error(1) // nolint: wrapcheck + return args.Get(0).(essentials.Conn), args.Error(1) // nolint: wrapcheck, forcetypeassert } func (m *MtglibNetworkMock) MakeHTTPClient(dialFunc func(ctx context.Context, network, address string) (essentials.Conn, error)) *http.Client { - return m.Called(dialFunc).Get(0).(*http.Client) + return m.Called(dialFunc).Get(0).(*http.Client) // nolint: forcetypeassert } diff --git a/internal/testlib/net_conn_mock.go b/internal/testlib/net_conn_mock.go index 476fe09..f4c455b 100644 --- a/internal/testlib/net_conn_mock.go +++ b/internal/testlib/net_conn_mock.go @@ -36,11 +36,11 @@ func (n *EssentialsConnMock) CloseWrite() error { } func (n *EssentialsConnMock) LocalAddr() net.Addr { - return n.Called().Get(0).(net.Addr) + return n.Called().Get(0).(net.Addr) // nolint: forcetypeassert } func (n *EssentialsConnMock) RemoteAddr() net.Addr { - return n.Called().Get(0).(net.Addr) + return n.Called().Get(0).(net.Addr) // nolint: forcetypeassert } func (n *EssentialsConnMock) SetDeadline(t time.Time) error { diff --git a/mtglib/internal/faketls/pools.go b/mtglib/internal/faketls/pools.go index 52288b1..e8dbcd2 100644 --- a/mtglib/internal/faketls/pools.go +++ b/mtglib/internal/faketls/pools.go @@ -12,7 +12,7 @@ var bytesBufferPool = sync.Pool{ } func acquireBytesBuffer() *bytes.Buffer { - return bytesBufferPool.Get().(*bytes.Buffer) + return bytesBufferPool.Get().(*bytes.Buffer) // nolint: forcetypeassert } func releaseBytesBuffer(b *bytes.Buffer) { diff --git a/mtglib/internal/faketls/record/pools.go b/mtglib/internal/faketls/record/pools.go index 16fa81f..e51c10c 100644 --- a/mtglib/internal/faketls/record/pools.go +++ b/mtglib/internal/faketls/record/pools.go @@ -11,7 +11,7 @@ var recordPool = sync.Pool{ } func AcquireRecord() *Record { - return recordPool.Get().(*Record) + return recordPool.Get().(*Record) // nolint: forcetypeassert } func ReleaseRecord(r *Record) { diff --git a/mtglib/internal/obfuscated2/pools.go b/mtglib/internal/obfuscated2/pools.go index 811c540..fd4a3da 100644 --- a/mtglib/internal/obfuscated2/pools.go +++ b/mtglib/internal/obfuscated2/pools.go @@ -21,7 +21,7 @@ var ( ) func acquireSha256Hasher() hash.Hash { - return sha256HasherPool.Get().(hash.Hash) + return sha256HasherPool.Get().(hash.Hash) // nolint: forcetypeassert } func releaseSha256Hasher(h hash.Hash) { @@ -30,7 +30,7 @@ func releaseSha256Hasher(h hash.Hash) { } func acquireBytesBuffer() *bytes.Buffer { - return bytesBufferPool.Get().(*bytes.Buffer) + return bytesBufferPool.Get().(*bytes.Buffer) // nolint: forcetypeassert } func releaseBytesBuffer(buf *bytes.Buffer) { diff --git a/mtglib/internal/obfuscated2/server_handshake_test.go b/mtglib/internal/obfuscated2/server_handshake_test.go index 89719bb..5321c9a 100644 --- a/mtglib/internal/obfuscated2/server_handshake_test.go +++ b/mtglib/internal/obfuscated2/server_handshake_test.go @@ -69,7 +69,7 @@ func (suite *ServerHandshakeTestSuite) TestSendToTelegram() { Once(). Run(func(args mock.Arguments) { message := make([]byte, len(messageToTelegram)) - suite.decryptor.XORKeyStream(message, args.Get(0).([]byte)) + suite.decryptor.XORKeyStream(message, args.Get(0).([]byte)) // nolint: forcetypeassert suite.Equal(messageToTelegram, message) }) @@ -89,7 +89,7 @@ func (suite *ServerHandshakeTestSuite) TestRecieveFromTelegram() { Run(func(args mock.Arguments) { message := make([]byte, len(messageFromTelegram)) suite.encryptor.XORKeyStream(message, messageFromTelegram) - copy(args.Get(0).([]byte), message) + copy(args.Get(0).([]byte), message) // nolint: forcetypeassert }) n, err := suite.proxyConn.Read(buffer) diff --git a/mtglib/internal/relay/pools.go b/mtglib/internal/relay/pools.go index 7b9371e..b853681 100644 --- a/mtglib/internal/relay/pools.go +++ b/mtglib/internal/relay/pools.go @@ -11,7 +11,7 @@ var copyBufferPool = sync.Pool{ } func acquireCopyBuffer() *[]byte { - return copyBufferPool.Get().(*[]byte) + return copyBufferPool.Get().(*[]byte) // nolint: forcetypeassert } func releaseCopyBuffer(buf *[]byte) { diff --git a/mtglib/proxy.go b/mtglib/proxy.go index dea9aa1..86e882f 100644 --- a/mtglib/proxy.go +++ b/mtglib/proxy.go @@ -106,7 +106,7 @@ func (p *Proxy) Serve(listener net.Listener) error { // nolint: cyclop } } - ipAddr := conn.RemoteAddr().(*net.TCPAddr).IP + ipAddr := conn.RemoteAddr().(*net.TCPAddr).IP // nolint: forcetypeassert logger := p.logger.BindStr("ip", ipAddr.String()) if p.whitelist != nil && !p.whitelist.Contains(ipAddr) { @@ -255,7 +255,10 @@ func (p *Proxy) doTelegramCall(ctx *streamContext) error { } p.eventStream.Send(ctx, - NewEventConnectedToDC(ctx.streamID, conn.RemoteAddr().(*net.TCPAddr).IP, ctx.dc)) + NewEventConnectedToDC(ctx.streamID, + conn.RemoteAddr().(*net.TCPAddr).IP, // nolint: forcetypeassert + ctx.dc), + ) return nil } @@ -316,7 +319,7 @@ func NewProxy(opts ProxyOpts) (*Proxy, error) { pool, err := ants.NewPoolWithFunc(opts.getConcurrency(), func(arg interface{}) { - proxy.ServeConn(arg.(essentials.Conn)) + proxy.ServeConn(arg.(essentials.Conn)) // nolint: forcetypeassert }, ants.WithLogger(opts.getLogger("ants")), ants.WithNonblocking(true)) diff --git a/mtglib/stream_context.go b/mtglib/stream_context.go index e1f2319..81752f2 100644 --- a/mtglib/stream_context.go +++ b/mtglib/stream_context.go @@ -49,7 +49,7 @@ func (s *streamContext) Close() { } func (s *streamContext) ClientIP() net.IP { - return s.clientConn.RemoteAddr().(*net.TCPAddr).IP + return s.clientConn.RemoteAddr().(*net.TCPAddr).IP // nolint: forcetypeassert } func newStreamContext(ctx context.Context, logger Logger, clientConn essentials.Conn) *streamContext { diff --git a/network/default.go b/network/default.go index 50855d9..e2a5ff0 100644 --- a/network/default.go +++ b/network/default.go @@ -36,7 +36,7 @@ func (d *defaultDialer) DialContext(ctx context.Context, network, address string return nil, fmt.Errorf("cannot set socket options: %w", err) } - return conn.(essentials.Conn), nil + return conn.(essentials.Conn), nil // nolint: forcetypeassert } // NewDefaultDialer build a new dialer which dials bypassing proxies diff --git a/network/init_internal_test.go b/network/init_internal_test.go index 6e63532..0b6e4a9 100644 --- a/network/init_internal_test.go +++ b/network/init_internal_test.go @@ -14,11 +14,11 @@ type DialerMock struct { func (d *DialerMock) Dial(network, address string) (essentials.Conn, error) { args := d.Called(network, address) - return args.Get(0).(essentials.Conn), args.Error(1) // nolint: wrapcheck + return args.Get(0).(essentials.Conn), args.Error(1) // nolint: wrapcheck, forcetypeassert } func (d *DialerMock) DialContext(ctx context.Context, network, address string) (essentials.Conn, error) { args := d.Called(ctx, network, address) - return args.Get(0).(essentials.Conn), args.Error(1) // nolint: wrapcheck + return args.Get(0).(essentials.Conn), args.Error(1) // nolint: wrapcheck, forcetypeassert } diff --git a/network/init_test.go b/network/init_test.go index 6e79a48..c5e2651 100644 --- a/network/init_test.go +++ b/network/init_test.go @@ -22,13 +22,13 @@ type DialerMock struct { func (d *DialerMock) Dial(network, address string) (essentials.Conn, error) { args := d.Called(network, address) - return args.Get(0).(essentials.Conn), args.Error(1) // nolint: wrapcheck + return args.Get(0).(essentials.Conn), args.Error(1) // nolint: wrapcheck, forcetypeassert } func (d *DialerMock) DialContext(ctx context.Context, network, address string) (essentials.Conn, error) { args := d.Called(ctx, network, address) - return args.Get(0).(essentials.Conn), args.Error(1) // nolint: wrapcheck + return args.Get(0).(essentials.Conn), args.Error(1) // nolint: wrapcheck, forcetypeassert } type HTTPServerTestSuite struct { diff --git a/network/sockopts.go b/network/sockopts.go index da99d09..938155b 100644 --- a/network/sockopts.go +++ b/network/sockopts.go @@ -10,13 +10,13 @@ import ( // // bufferSize setting is deprecated and ignored. func SetClientSocketOptions(conn net.Conn, bufferSize int) error { - return setCommonSocketOptions(conn.(*net.TCPConn)) + return setCommonSocketOptions(conn.(*net.TCPConn)) // nolint: forcetypeassert } // SetServerSocketOptions tunes a TCP socket that represents a connection to // remote server like Telegram or fronting domain (but not end user). func SetServerSocketOptions(conn net.Conn, bufferSize int) error { - return setCommonSocketOptions(conn.(*net.TCPConn)) + return setCommonSocketOptions(conn.(*net.TCPConn)) // nolint: forcetypeassert } func setCommonSocketOptions(conn *net.TCPConn) error { diff --git a/stats/pools.go b/stats/pools.go index b9b6255..6c81d20 100644 --- a/stats/pools.go +++ b/stats/pools.go @@ -11,7 +11,7 @@ var streamInfoPool = sync.Pool{ } func acquireStreamInfo() *streamInfo { - return streamInfoPool.Get().(*streamInfo) + return streamInfoPool.Get().(*streamInfo) // nolint: forcetypeassert } func releaseStreamInfo(info *streamInfo) {