Upgrade golangci-lint for 1.42

This commit is contained in:
9seconds
2021-08-30 11:46:32 +03:00
parent 7718f62477
commit 3e0880f6b4
29 changed files with 90 additions and 89 deletions
+1 -1
View File
@@ -72,7 +72,7 @@ jobs:
- name: Run linter
uses: golangci/golangci-lint-action@v2
with:
version: v1.37.1
version: v1.42.0
docker:
name: Docker
+1 -1
View File
@@ -4,7 +4,7 @@ APP_NAME := $(IMAGE_NAME)
CC_BINARIES := $(shell bash -c "echo -n $(APP_NAME)-{linux,freebsd,openbsd}-{386,amd64} $(APP_NAME)-linux-{arm,arm64}")
GOLANGCI_LINT_VERSION := v1.37.1
GOLANGCI_LINT_VERSION := v1.42.0
VERSION_GO := $(shell go version)
VERSION_DATE := $(shell date -Ru)
+30 -30
View File
@@ -79,29 +79,29 @@ const (
type Config struct {
Bind *net.TCPAddr `json:"bind"`
PublicIPv4 *net.TCPAddr `json:"public_ipv4"`
PublicIPv6 *net.TCPAddr `json:"public_ipv6"`
StatsBind *net.TCPAddr `json:"stats_bind"`
StatsdAddr *net.TCPAddr `json:"stats_addr"`
StatsdTagsFormat *statsd.TagFormat `json:"statsd_tags_format"`
PublicIPv4 *net.TCPAddr `json:"public_ipv4"` // nolint: tagliatelle
PublicIPv6 *net.TCPAddr `json:"public_ipv6"` // nolint: tagliatelle
StatsBind *net.TCPAddr `json:"stats_bind"` // nolint: tagliatelle
StatsdAddr *net.TCPAddr `json:"stats_addr"` // nolint: tagliatelle
StatsdTagsFormat *statsd.TagFormat `json:"statsd_tags_format"` // nolint: tagliatelle
StatsNamespace string `json:"stats_namespace"`
CloakHost string `json:"cloak_host"`
StatsdTags map[string]string `json:"statsd_tags"`
StatsNamespace string `json:"stats_namespace"` // nolint: tagliatelle
CloakHost string `json:"cloak_host"` // nolint: tagliatelle
StatsdTags map[string]string `json:"statsd_tags"` // nolint: tagliatelle
WriteBuffer int `json:"write_buffer"`
ReadBuffer int `json:"read_buffer"`
CloakPort int `json:"cloak_port"`
WriteBuffer int `json:"write_buffer"` // nolint: tagliatelle
ReadBuffer int `json:"read_buffer"` // nolint: tagliatelle
CloakPort int `json:"cloak_port"` // nolint: tagliatelle
AntiReplayMaxSize int `json:"anti_replay_max_size"`
AntiReplayMaxSize int `json:"anti_replay_max_size"` // nolint: tagliatelle
MultiplexPerConnection int `json:"multiplex_per_connection"`
MultiplexPerConnection int `json:"multiplex_per_connection"` // nolint: tagliatelle
Debug bool `json:"debug"`
Verbose bool `json:"verbose"`
SecretMode SecretMode `json:"secret_mode"`
PreferIP PreferIP `json:"prefer_ip"`
NTPServers []string `json:"ntp_servers"`
SecretMode SecretMode `json:"secret_mode"` // nolint: tagliatelle
PreferIP PreferIP `json:"prefer_ip"` // nolint: tagliatelle
NTPServers []string `json:"ntp_servers"` // nolint: tagliatelle
Secret []byte `json:"secret"`
AdTag []byte `json:"adtag"`
@@ -164,11 +164,11 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen, cyclop
for _, opt := range options {
switch opt.Option {
case OptionTypeDebug:
C.Debug = opt.Value.(bool)
C.Debug = opt.Value.(bool) // nolint: forcetypeassert
case OptionTypeVerbose:
C.Verbose = opt.Value.(bool)
C.Verbose = opt.Value.(bool) // nolint: forcetypeassert
case OptionTypePreferIP:
value := opt.Value.(string)
value := opt.Value.(string) // nolint: forcetypeassert
switch value {
case "ipv4":
C.PreferIP = PreferIPv4
@@ -178,25 +178,25 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen, cyclop
return fmt.Errorf("incorrect direct IP mode %s", value)
}
case OptionTypeBind:
C.Bind = opt.Value.(*net.TCPAddr)
C.Bind = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert
case OptionTypePublicIPv4:
C.PublicIPv4 = opt.Value.(*net.TCPAddr)
C.PublicIPv4 = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert
if C.PublicIPv4 == nil {
C.PublicIPv4 = &net.TCPAddr{}
}
case OptionTypePublicIPv6:
C.PublicIPv6 = opt.Value.(*net.TCPAddr)
C.PublicIPv6 = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert
if C.PublicIPv6 == nil {
C.PublicIPv6 = &net.TCPAddr{}
}
case OptionTypeStatsBind:
C.StatsBind = opt.Value.(*net.TCPAddr)
C.StatsBind = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert
case OptionTypeStatsNamespace:
C.StatsNamespace = opt.Value.(string)
C.StatsNamespace = opt.Value.(string) // nolint: forcetypeassert
case OptionTypeStatsdAddress:
C.StatsdAddr = opt.Value.(*net.TCPAddr)
C.StatsdAddr = opt.Value.(*net.TCPAddr) // nolint: forcetypeassert
case OptionTypeStatsdTagsFormat:
value := opt.Value.(string)
value := opt.Value.(string) // nolint: forcetypeassert
switch value {
case "datadog":
C.StatsdTagsFormat = statsd.TagFormatDatadog
@@ -206,7 +206,7 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen, cyclop
return fmt.Errorf("incorrect statsd tag %s", value)
}
case OptionTypeStatsdTags:
C.StatsdTags = opt.Value.(map[string]string)
C.StatsdTags = opt.Value.(map[string]string) // nolint: forcetypeassert
case OptionTypeWriteBufferSize:
C.WriteBuffer = int(opt.Value.(units.Base2Bytes))
case OptionTypeReadBufferSize:
@@ -218,14 +218,14 @@ func Init(options ...Opt) error { // nolint: gocyclo, funlen, cyclop
case OptionTypeMultiplexPerConnection:
C.MultiplexPerConnection = int(opt.Value.(uint))
case OptionTypeNTPServers:
C.NTPServers = opt.Value.([]string)
C.NTPServers = opt.Value.([]string) // nolint: forcetypeassert
if len(C.NTPServers) == 0 {
return errors.New("ntp server list is empty")
}
case OptionTypeSecret:
C.Secret = opt.Value.([]byte)
C.Secret = opt.Value.([]byte) // nolint: forcetypeassert
case OptionTypeAdtag:
C.AdTag = opt.Value.([]byte)
C.AdTag = opt.Value.([]byte) // nolint: forcetypeassert
default:
return fmt.Errorf("unknown tag %v", opt.Option)
}
+1 -1
View File
@@ -41,7 +41,7 @@ func fetchIP(ctx context.Context, network string) (net.IP, error) {
Timeout: ifconfigTimeout,
Transport: &http.Transport{
DialContext: func(ctx context.Context, _, addr string) (net.Conn, error) {
return dialer.DialContext(ctx, network, addr)
return dialer.DialContext(ctx, network, addr) // nolint: wrapcheck
},
},
}
+5 -5
View File
@@ -8,16 +8,16 @@ import (
)
type URLs struct {
TG string `json:"tg_url"`
TMe string `json:"tme_url"`
TGQRCode string `json:"tg_qrcode"`
TMeQRCode string `json:"tme_qrcode"`
TG string `json:"tg_url"` // nolint: tagliatelle
TMe string `json:"tme_url"` // nolint: tagliatelle
TGQRCode string `json:"tg_qrcode"` // nolint: tagliatelle
TMeQRCode string `json:"tme_qrcode"` // nolint: tagliatelle
}
type IPURLs struct {
IPv4 *URLs `json:"ipv4,omitempty"`
IPv6 *URLs `json:"ipv6,omitempty"`
BotSecret string `json:"secret_for_mtproxybot"`
BotSecret string `json:"secret_for_mtproxybot"` // nolint: tagliatelle
}
func GetURLs() (urls IPURLs) {
+1 -1
View File
@@ -18,7 +18,7 @@ func (h *hub) Register(req *protocol.TelegramRequest) (*ProxyConn, error) {
}
func (h *hub) getMux(req *protocol.TelegramRequest) *mux {
var key int32 = 32767 + int32(req.ClientProtocol.DC()) + 100000*int32(req.ClientProtocol.ConnectionProtocol())
key := 32767 + int32(req.ClientProtocol.DC()) + 100000*int32(req.ClientProtocol.ConnectionProtocol())
h.mutex.RLock()
m, ok := h.muxes[key]
+5 -5
View File
@@ -45,14 +45,14 @@ func (c *ClientProtocol) Handshake(socket conntypes.StreamReadWriteCloser) (conn
}
decHasher := sha256.New()
decHasher.Write(fm.Key()) // nolint: errcheck
decHasher.Write(config.C.Secret) // nolint: errcheck
decHasher.Write(fm.Key())
decHasher.Write(config.C.Secret)
decryptor := utils.MakeStreamCipher(decHasher.Sum(nil), fm.IV())
invertedFrame := fm.Invert()
encHasher := sha256.New()
encHasher.Write(invertedFrame.Key()) // nolint: errcheck
encHasher.Write(config.C.Secret) // nolint: errcheck
encHasher.Write(invertedFrame.Key())
encHasher.Write(config.C.Secret)
encryptor := utils.MakeStreamCipher(encHasher.Sum(nil), invertedFrame.IV())
decryptedFrame := Frame{}
@@ -106,7 +106,7 @@ type handshakeReader struct {
}
func (h handshakeReader) Read(p []byte) (int, error) {
return h.parent.ReadTimeout(p, clientProtocolHandshakeTimeout)
return h.parent.ReadTimeout(p, clientProtocolHandshakeTimeout) // nolint: wrapcheck
}
func MakeClientProtocol() protocol.ClientProtocol {
+3 -6
View File
@@ -4,7 +4,6 @@ import (
"io"
"sync"
"github.com/9seconds/mtg/conntypes"
"github.com/9seconds/mtg/obfuscated2"
"github.com/9seconds/mtg/protocol"
"go.uber.org/zap"
@@ -18,16 +17,14 @@ func directConnection(request *protocol.TelegramRequest) error {
return err // nolint: wrapcheck
}
telegramConn := telegramConnRaw.(conntypes.StreamReadWriteCloser)
defer telegramConn.Close()
defer telegramConnRaw.Close()
wg := &sync.WaitGroup{}
wg.Add(2)
go directPipe(telegramConn, request.ClientConn, wg, request.Logger)
go directPipe(telegramConnRaw, request.ClientConn, wg, request.Logger)
go directPipe(request.ClientConn, telegramConn, wg, request.Logger)
go directPipe(request.ClientConn, telegramConnRaw, wg, request.Logger)
wg.Wait()
+2 -2
View File
@@ -49,8 +49,8 @@ func (s ServerHello) WelcomePacket() []byte {
packet := buf.Bytes()
mac := hmac.New(sha256.New, config.C.Secret)
mac.Write(s.clientHello.Random[:]) // nolint: errcheck
mac.Write(packet) // nolint: errcheck
mac.Write(s.clientHello.Random[:])
mac.Write(packet)
copy(packet[11:], mac.Sum(nil))
return packet
+1 -1
View File
@@ -6,7 +6,7 @@ import (
)
func InitTCP(conn net.Conn, readBufferSize int, writeBufferSize int) error {
tcpConn := conn.(*net.TCPConn)
tcpConn := conn.(*net.TCPConn) // nolint: forcetypeassert
if err := tcpConn.SetNoDelay(true); err != nil {
return fmt.Errorf("cannot set TCP_NO_DELAY: %w", err)
+1
View File
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows
package utils
+1
View File
@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package utils
+1
View File
@@ -1,3 +1,4 @@
//go:build !windows
// +build !windows
package utils
+1
View File
@@ -1,3 +1,4 @@
//go:build windows
// +build windows
package utils
+1 -1
View File
@@ -136,7 +136,7 @@ func (w *wrapperMtprotoFrame) Write(p conntypes.Packet) error {
}
func (w *wrapperMtprotoFrame) Close() error {
return w.parent.Close()
return w.parent.Close() // nolint: wrapcheck
}
func (w *wrapperMtprotoFrame) Conn() net.Conn {
+1 -1
View File
@@ -104,7 +104,7 @@ func (w *wrapperClientAbridged) Write(packet conntypes.Packet, acks *conntypes.C
}
func (w *wrapperClientAbridged) Close() error {
return w.parent.Close()
return w.parent.Close() // nolint: wrapcheck
}
func (w *wrapperClientAbridged) Conn() net.Conn {
+1 -1
View File
@@ -63,7 +63,7 @@ func (w *wrapperClientIntermediate) Write(packet conntypes.Packet, acks *conntyp
}
func (w *wrapperClientIntermediate) Close() error {
return w.parent.Close()
return w.parent.Close() // nolint: wrapcheck
}
func (w *wrapperClientIntermediate) Conn() net.Conn {
+1 -1
View File
@@ -46,7 +46,7 @@ func (w *wrapperProxy) Write(packet conntypes.Packet, acks *conntypes.Connection
buf.Grow(len(packet))
buf.Write(packet)
return w.proxy.Write(buf.Bytes())
return w.proxy.Write(buf.Bytes()) // nolint: wrapcheck
}
func (w *wrapperProxy) Read(acks *conntypes.ConnectionAcks) (conntypes.Packet, error) {
+1 -1
View File
@@ -36,7 +36,7 @@ func (w *wrapperPing) Write(p []byte) (int, error) {
}
func (w *wrapperPing) Close() error {
return w.parent.Close()
return w.parent.Close() // nolint: wrapcheck
}
func NewPing(ctx context.Context, parent io.ReadWriteCloser, channelPing chan<- struct{}) io.ReadWriteCloser {
+3 -3
View File
@@ -26,7 +26,7 @@ func (w *wrapperBlockCipher) Write(p []byte) (int, error) {
return 0, err
}
return w.parent.Write(encrypted)
return w.parent.Write(encrypted) // nolint: wrapcheck
}
func (w *wrapperBlockCipher) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
@@ -35,7 +35,7 @@ func (w *wrapperBlockCipher) WriteTimeout(p []byte, timeout time.Duration) (int,
return 0, err
}
return w.parent.WriteTimeout(encrypted, timeout)
return w.parent.WriteTimeout(encrypted, timeout) // nolint: wrapcheck
}
func (w *wrapperBlockCipher) encrypt(p []byte) ([]byte, error) {
@@ -50,7 +50,7 @@ func (w *wrapperBlockCipher) encrypt(p []byte) ([]byte, error) {
}
func (w *wrapperBlockCipher) Close() error {
return w.parent.Close()
return w.parent.Close() // nolint: wrapcheck
}
func (w *wrapperBlockCipher) Conn() net.Conn {
+1 -1
View File
@@ -33,7 +33,7 @@ func (b *bufferedReader) ReadTimeout(p []byte, _ time.Duration) (int, error) {
func (b *bufferedReader) flush(p []byte) (int, error) {
if b.buf.Len() > len(p) {
return b.buf.Read(p)
return b.buf.Read(p) // nolint: wrapcheck
}
sizeToReturn := b.buf.Len()
+1 -1
View File
@@ -70,7 +70,7 @@ func (w *wrapperConn) Read(p []byte) (int, error) {
func (w *wrapperConn) Close() error {
w.logger.Debugw("Close connection")
return w.parent.Close()
return w.parent.Close() // nolint: wrapcheck
}
func (w *wrapperConn) Conn() net.Conn {
+5 -5
View File
@@ -23,7 +23,7 @@ func (w *wrapperCtx) WriteTimeout(p []byte, timeout time.Duration) (int, error)
return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
default:
return w.parent.WriteTimeout(p, timeout)
return w.parent.WriteTimeout(p, timeout) // nolint: wrapcheck
}
}
@@ -34,7 +34,7 @@ func (w *wrapperCtx) Write(p []byte) (int, error) {
return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
default:
return w.parent.Write(p)
return w.parent.Write(p) // nolint: wrapcheck
}
}
@@ -45,7 +45,7 @@ func (w *wrapperCtx) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
default:
return w.parent.ReadTimeout(p, timeout)
return w.parent.ReadTimeout(p, timeout) // nolint: wrapcheck
}
}
@@ -56,14 +56,14 @@ func (w *wrapperCtx) Read(p []byte) (int, error) {
return 0, fmt.Errorf("cannot write because context was closed: %w", w.ctx.Err())
default:
return w.parent.Read(p)
return w.parent.Read(p) // nolint: wrapcheck
}
}
func (w *wrapperCtx) Close() error {
w.cancel()
return w.parent.Close()
return w.parent.Close() // nolint: wrapcheck
}
func (w *wrapperCtx) Conn() net.Conn {
+3 -3
View File
@@ -20,7 +20,7 @@ type wrapperFakeTLS struct {
func (w *wrapperFakeTLS) Write(p []byte) (int, error) {
return w.write(p, func(b []byte) (int, error) {
return w.parent.Write(b)
return w.parent.Write(b) // nolint: wrapcheck
})
}
@@ -30,7 +30,7 @@ func (w *wrapperFakeTLS) WriteTimeout(p []byte, timeout time.Duration) (int, err
return w.write(p, func(b []byte) (int, error) {
elapsed := time.Since(startTime)
if elapsed > timeout {
return w.parent.WriteTimeout(b, timeout-elapsed)
return w.parent.WriteTimeout(b, timeout-elapsed) // nolint: wrapcheck
}
return 0, errors.New("timeout")
@@ -73,7 +73,7 @@ func (w *wrapperFakeTLS) RemoteAddr() *net.TCPAddr {
}
func (w *wrapperFakeTLS) Close() error {
return w.parent.Close()
return w.parent.Close() // nolint: wrapcheck
}
func NewFakeTLS(socket conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser {
+3 -3
View File
@@ -48,7 +48,7 @@ func (w *wrapperObfuscated2) WriteTimeout(p []byte, timeout time.Duration) (int,
w.encryptor.XORKeyStream(buf, buf)
return w.parent.WriteTimeout(buf, timeout)
return w.parent.WriteTimeout(buf, timeout) // nolint: wrapcheck
}
func (w *wrapperObfuscated2) Write(p []byte) (int, error) {
@@ -60,7 +60,7 @@ func (w *wrapperObfuscated2) Write(p []byte) (int, error) {
w.encryptor.XORKeyStream(buf, buf)
return w.parent.Write(buf)
return w.parent.Write(buf) // nolint: wrapcheck
}
func (w *wrapperObfuscated2) Conn() net.Conn {
@@ -80,7 +80,7 @@ func (w *wrapperObfuscated2) RemoteAddr() *net.TCPAddr {
}
func (w *wrapperObfuscated2) Close() error {
return w.parent.Close()
return w.parent.Close() // nolint: wrapcheck
}
func NewObfuscated2(socket conntypes.StreamReadWriteCloser,
+5 -5
View File
@@ -24,25 +24,25 @@ type wrapperRewind struct {
}
func (w *wrapperRewind) Write(p []byte) (int, error) {
return w.parent.Write(p)
return w.parent.Write(p) // nolint: wrapcheck
}
func (w *wrapperRewind) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
return w.parent.WriteTimeout(p, timeout)
return w.parent.WriteTimeout(p, timeout) // nolint: wrapcheck
}
func (w *wrapperRewind) Read(p []byte) (int, error) {
w.mutex.Lock()
defer w.mutex.Unlock()
return w.activeReader.Read(p)
return w.activeReader.Read(p) // nolint: wrapcheck
}
func (w *wrapperRewind) ReadTimeout(p []byte, _ time.Duration) (int, error) {
w.mutex.Lock()
defer w.mutex.Unlock()
return w.activeReader.Read(p)
return w.activeReader.Read(p) // nolint: wrapcheck
}
func (w *wrapperRewind) Conn() net.Conn {
@@ -64,7 +64,7 @@ func (w *wrapperRewind) RemoteAddr() *net.TCPAddr {
func (w *wrapperRewind) Close() error {
w.buf.Reset()
return w.parent.Close()
return w.parent.Close() // nolint: wrapcheck
}
func (w *wrapperRewind) Rewind() {
+4 -4
View File
@@ -17,19 +17,19 @@ type wrapperTelegramStats struct {
}
func (w *wrapperTelegramStats) Write(p []byte) (int, error) {
return w.parent.Write(p)
return w.parent.Write(p) // nolint: wrapcheck
}
func (w *wrapperTelegramStats) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
return w.parent.WriteTimeout(p, timeout)
return w.parent.WriteTimeout(p, timeout) // nolint: wrapcheck
}
func (w *wrapperTelegramStats) Read(p []byte) (int, error) {
return w.parent.Read(p)
return w.parent.Read(p) // nolint: wrapcheck
}
func (w *wrapperTelegramStats) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
return w.parent.ReadTimeout(p, timeout)
return w.parent.ReadTimeout(p, timeout) // nolint: wrapcheck
}
func (w *wrapperTelegramStats) Conn() net.Conn {
+1 -1
View File
@@ -58,7 +58,7 @@ func (w *wrapperTrafficStats) RemoteAddr() *net.TCPAddr {
}
func (w *wrapperTrafficStats) Close() error {
return w.parent.Close()
return w.parent.Close() // nolint: wrapcheck
}
func NewTrafficStats(parent conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser {
+5 -5
View File
@@ -18,23 +18,23 @@ type wrapperTimeout struct {
}
func (w *wrapperTimeout) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
return w.parent.WriteTimeout(p, timeout)
return w.parent.WriteTimeout(p, timeout) // nolint: wrapcheck
}
func (w *wrapperTimeout) Write(p []byte) (int, error) {
return w.parent.WriteTimeout(p, timeoutWrite)
return w.parent.WriteTimeout(p, timeoutWrite) // nolint: wrapcheck
}
func (w *wrapperTimeout) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
return w.parent.ReadTimeout(p, timeout)
return w.parent.ReadTimeout(p, timeout) // nolint: wrapcheck
}
func (w *wrapperTimeout) Read(p []byte) (int, error) {
return w.parent.ReadTimeout(p, timeoutRead)
return w.parent.ReadTimeout(p, timeoutRead) // nolint: wrapcheck
}
func (w *wrapperTimeout) Close() error {
return w.parent.Close()
return w.parent.Close() // nolint: wrapcheck
}
func (w *wrapperTimeout) Conn() net.Conn {