Bläddra i källkod

Update golangci-linter

tags/v1.0.8
9seconds 5 år sedan
förälder
incheckning
33b1a5426c

+ 1
- 1
.golangci.toml Visa fil

@@ -10,4 +10,4 @@ format = "colored-line-number"
10 10
 
11 11
 [linters]
12 12
 enable-all = true
13
-disable = ["gochecknoglobals", "gas", "gomnd", "goerr113"]
13
+disable = ["gochecknoglobals", "gas", "gomnd", "goerr113", "exhaustivestruct"]

+ 1
- 1
Makefile Visa fil

@@ -4,7 +4,7 @@ APP_NAME     := $(IMAGE_NAME)
4 4
 
5 5
 CC_BINARIES  := $(shell bash -c "echo -n $(APP_NAME)-{linux,freebsd,openbsd}-{386,amd64} $(APP_NAME)-linux-{arm,arm64}")
6 6
 
7
-GOLANGCI_LINT_VERSION := v1.31.0
7
+GOLANGCI_LINT_VERSION := v1.37.1
8 8
 
9 9
 VERSION_GO         := $(shell go version)
10 10
 VERSION_DATE       := $(shell date -Ru)

+ 1
- 1
cli/proxy.go Visa fil

@@ -19,7 +19,7 @@ import (
19 19
 	"go.uber.org/zap/zapcore"
20 20
 )
21 21
 
22
-func Proxy() error { // nolint: funlen
22
+func Proxy() error { // nolint: funlen,cyclop
23 23
 	ctx := utils.GetSignalContext()
24 24
 
25 25
 	atom := zap.NewAtomicLevel()

+ 2
- 2
cli/utils.go Visa fil

@@ -9,7 +9,7 @@ import (
9 9
 
10 10
 func Fatal(arg interface{}) {
11 11
 	if value, ok := arg.(error); ok {
12
-		arg = fmt.Errorf("fatal error: %+v", value)
12
+		arg = fmt.Errorf("fatal error: %+v", value) // nolint: errorlint
13 13
 	}
14 14
 
15 15
 	PrintStderr(arg)
@@ -21,7 +21,7 @@ func PrintStderr(args ...interface{}) {
21 21
 }
22 22
 
23 23
 func PrintStdout(args ...interface{}) {
24
-	fmt.Println(args...)
24
+	fmt.Println(args...) // nolint: forbidigo
25 25
 }
26 26
 
27 27
 func PrintJSONStderr(data interface{}) {

+ 1
- 1
config/config.go Visa fil

@@ -160,7 +160,7 @@ type Opt struct {
160 160
 
161 161
 var C = Config{}
162 162
 
163
-func Init(options ...Opt) error { // nolint: gocyclo, funlen
163
+func Init(options ...Opt) error { // nolint: gocyclo, funlen, cyclop
164 164
 	for _, opt := range options {
165 165
 		switch opt.Option {
166 166
 		case OptionTypeDebug:

+ 2
- 2
faketls/client_protocol.go Visa fil

@@ -52,10 +52,10 @@ func (c *ClientProtocol) Handshake(socket conntypes.StreamReadWriteCloser) (conn
52 52
 
53 53
 	conn, err := c.ClientProtocol.Handshake(conn)
54 54
 	if err != nil {
55
-		return nil, err
55
+		return nil, err // nolint: wrapcheck
56 56
 	}
57 57
 
58
-	return conn, err
58
+	return conn, err // nolint: wrapcheck
59 59
 }
60 60
 
61 61
 func (c *ClientProtocol) tlsHandshake(conn io.ReadWriter) error {

+ 1
- 1
hub/connection.go Visa fil

@@ -30,7 +30,7 @@ type connection struct {
30 30
 	channelConnDetach chan conntypes.ConnID
31 31
 }
32 32
 
33
-func (c *connection) run() {
33
+func (c *connection) run() { // nolint: cyclop
34 34
 	defer c.Close()
35 35
 
36 36
 	ttl := time.NewTimer(connectionTTL)

+ 1
- 1
mtproto/protocol.go Visa fil

@@ -51,7 +51,7 @@ func doRPCNonceRequest(conn conntypes.BasePacketWriter) (*rpc.NonceRequest, erro
51 51
 	}
52 52
 
53 53
 	if err := conn.Write(rpcNonceReq.Bytes()); err != nil {
54
-		return nil, err
54
+		return nil, err // nolint: wrapcheck
55 55
 	}
56 56
 
57 57
 	return rpcNonceReq, nil

+ 1
- 1
proxy/direct.go Visa fil

@@ -15,7 +15,7 @@ const directPipeBufferSize = 1024
15 15
 func directConnection(request *protocol.TelegramRequest) error {
16 16
 	telegramConnRaw, err := obfuscated2.TelegramProtocol(request)
17 17
 	if err != nil {
18
-		return err
18
+		return err // nolint: wrapcheck
19 19
 	}
20 20
 
21 21
 	telegramConn := telegramConnRaw.(conntypes.StreamReadWriteCloser)

+ 5
- 4
stats/stats_statsd.go Visa fil

@@ -168,17 +168,18 @@ func (s *statsStatsd) prepareVals(metric string, tags []*statsStatsdTag) (string
168 168
 
169 169
 func (s *statsStatsd) initGauge(metric, key string, tags []statsd.Tag) {
170 170
 	s.seenMutex.RLock()
171
-	_, ok := s.seen[key]
172
-	s.seenMutex.RUnlock()
171
+	if _, ok := s.seen[key]; ok {
172
+		s.seenMutex.RUnlock()
173 173
 
174
-	if ok {
175 174
 		return
175
+	} else { // nolint: golint,revive
176
+		s.seenMutex.RUnlock()
176 177
 	}
177 178
 
178 179
 	s.seenMutex.Lock()
179 180
 	defer s.seenMutex.Unlock()
180 181
 
181
-	if _, ok = s.seen[key]; !ok {
182
+	if _, ok := s.seen[key]; !ok {
182 183
 		s.seen[key] = struct{}{}
183 184
 		s.client.Gauge(metric, 0, tags...)
184 185
 	}

+ 1
- 1
telegram/api/api.go Visa fil

@@ -40,5 +40,5 @@ func request(url string) (io.ReadCloser, error) {
40 40
 		return nil, fmt.Errorf("cannot perform a request: %w", err)
41 41
 	}
42 42
 
43
-	return resp.Body, err
43
+	return resp.Body, err // nolint: wrapcheck
44 44
 }

+ 6
- 6
tlstypes/consts.go Visa fil

@@ -20,9 +20,9 @@ const (
20 20
 type CipherSuiteType uint8
21 21
 
22 22
 const (
23
-	CipherSuiteType_TLS_AES_128_GCM_SHA256       CipherSuiteType = iota // nolint: stylecheck,golint
24
-	CipherSuiteType_TLS_AES_256_GCM_SHA384                              // nolint: stylecheck,golint
25
-	CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256                        // nolint: stylecheck,golint
23
+	CipherSuiteType_TLS_AES_128_GCM_SHA256       CipherSuiteType = iota // nolint: stylecheck,golint,revive
24
+	CipherSuiteType_TLS_AES_256_GCM_SHA384                              // nolint: stylecheck,golint,revive
25
+	CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256                        // nolint: stylecheck,golint,revive
26 26
 )
27 27
 
28 28
 func (c CipherSuiteType) Bytes() []byte {
@@ -69,9 +69,9 @@ var (
69 69
 	Version12Bytes = []byte{0x03, 0x03}
70 70
 	Version13Bytes = []byte{0x03, 0x04}
71 71
 
72
-	CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes       = []byte{0x13, 0x01} // nolint: stylecheck,golint
73
-	CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes       = []byte{0x13, 0x02} // nolint: stylecheck,golint
74
-	CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes = []byte{0x13, 0x03} // nolint: stylecheck,golint
72
+	CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes       = []byte{0x13, 0x01} // nolint: stylecheck,golint,revive
73
+	CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes       = []byte{0x13, 0x02} // nolint: stylecheck,golint,revive
74
+	CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes = []byte{0x13, 0x03} // nolint: stylecheck,golint,revive
75 75
 )
76 76
 
77 77
 type Byter interface {

+ 1
- 1
utils/read_full.go Visa fil

@@ -11,7 +11,7 @@ func ReadFull(src io.Reader) (rv []byte, err error) {
11 11
 	for n == len(buf) {
12 12
 		n, err = src.Read(buf)
13 13
 		if err != nil {
14
-			return nil, err
14
+			return nil, err // nolint: wrapcheck
15 15
 		}
16 16
 
17 17
 		rv = append(rv, buf[:n]...)

+ 2
- 2
wrappers/packet/mtproto_frame.go Visa fil

@@ -40,7 +40,7 @@ type wrapperMtprotoFrame struct {
40 40
 	writeSeqNo int32
41 41
 }
42 42
 
43
-func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funlen
43
+func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funlen, cyclop
44 44
 	buf := &bytes.Buffer{}
45 45
 
46 46
 	sum := crc32.NewIEEE()
@@ -132,7 +132,7 @@ func (w *wrapperMtprotoFrame) Write(p conntypes.Packet) error {
132 132
 
133 133
 	_, err := w.parent.Write(buf.Bytes())
134 134
 
135
-	return err
135
+	return err // nolint: wrapcheck
136 136
 }
137 137
 
138 138
 func (w *wrapperMtprotoFrame) Close() error {

+ 2
- 2
wrappers/rwc/ping.go Visa fil

@@ -20,7 +20,7 @@ func (w *wrapperPing) Read(p []byte) (int, error) {
20 20
 		}
21 21
 	}
22 22
 
23
-	return n, err
23
+	return n, err // nolint: wrapcheck
24 24
 }
25 25
 
26 26
 func (w *wrapperPing) Write(p []byte) (int, error) {
@@ -32,7 +32,7 @@ func (w *wrapperPing) Write(p []byte) (int, error) {
32 32
 		}
33 33
 	}
34 34
 
35
-	return n, err
35
+	return n, err // nolint: wrapcheck
36 36
 }
37 37
 
38 38
 func (w *wrapperPing) Close() error {

+ 2
- 2
wrappers/stream/conn.go Visa fil

@@ -43,7 +43,7 @@ func (w *wrapperConn) Write(p []byte) (int, error) {
43 43
 		w.Close()
44 44
 	}
45 45
 
46
-	return n, err
46
+	return n, err // nolint: wrapcheck
47 47
 }
48 48
 
49 49
 func (w *wrapperConn) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
@@ -64,7 +64,7 @@ func (w *wrapperConn) Read(p []byte) (int, error) {
64 64
 		w.Close()
65 65
 	}
66 66
 
67
-	return n, err
67
+	return n, err // nolint: wrapcheck
68 68
 }
69 69
 
70 70
 func (w *wrapperConn) Close() error {

+ 1
- 1
wrappers/stream/faketls.go Visa fil

@@ -85,7 +85,7 @@ func NewFakeTLS(socket conntypes.StreamReadWriteCloser) conntypes.StreamReadWrit
85 85
 		for {
86 86
 			rec, err := tlstypes.ReadRecord(faketls.parent)
87 87
 			if err != nil {
88
-				return nil, err
88
+				return nil, err // nolint: wrapcheck
89 89
 			}
90 90
 
91 91
 			switch rec.Type {

+ 1
- 1
wrappers/stream/obfuscated2.go Visa fil

@@ -31,7 +31,7 @@ func (w *wrapperObfuscated2) ReadTimeout(p []byte, timeout time.Duration) (int,
31 31
 func (w *wrapperObfuscated2) Read(p []byte) (int, error) {
32 32
 	n, err := w.parent.Read(p)
33 33
 	if err != nil {
34
-		return n, err
34
+		return n, err // nolint: wrapcheck
35 35
 	}
36 36
 
37 37
 	w.decryptor.XORKeyStream(p, p[:n])

+ 7
- 6
wrappers/stream/rewind.go Visa fil

@@ -2,6 +2,7 @@ package stream
2 2
 
3 3
 import (
4 4
 	"bytes"
5
+	"errors"
5 6
 	"io"
6 7
 	"net"
7 8
 	"sync"
@@ -36,8 +37,8 @@ func (w *wrapperRewind) Read(p []byte) (int, error) {
36 37
 	defer w.mutex.Unlock()
37 38
 
38 39
 	if w.rewinded {
39
-		if n, err := w.buf.Read(p); err != io.EOF {
40
-			return n, err
40
+		if n, err := w.buf.Read(p); errors.Is(err, io.EOF) {
41
+			return n, err // nolint: wrapcheck
41 42
 		}
42 43
 	}
43 44
 
@@ -47,7 +48,7 @@ func (w *wrapperRewind) Read(p []byte) (int, error) {
47 48
 		w.buf.Write(p[:n])
48 49
 	}
49 50
 
50
-	return n, err
51
+	return n, err // nolint: wrapcheck
51 52
 }
52 53
 
53 54
 func (w *wrapperRewind) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
@@ -55,8 +56,8 @@ func (w *wrapperRewind) ReadTimeout(p []byte, timeout time.Duration) (int, error
55 56
 	defer w.mutex.Unlock()
56 57
 
57 58
 	if w.rewinded {
58
-		if n, err := w.buf.Read(p); err != io.EOF {
59
-			return n, err
59
+		if n, err := w.buf.Read(p); errors.Is(err, io.EOF) {
60
+			return n, err // nolint: wrapcheck
60 61
 		}
61 62
 	}
62 63
 
@@ -66,7 +67,7 @@ func (w *wrapperRewind) ReadTimeout(p []byte, timeout time.Duration) (int, error
66 67
 		w.buf.Write(p[:n])
67 68
 	}
68 69
 
69
-	return n, err
70
+	return n, err // nolint: wrapcheck
70 71
 }
71 72
 
72 73
 func (w *wrapperRewind) Conn() net.Conn {

+ 1
- 1
wrappers/stream/stats_telegram.go Visa fil

@@ -56,7 +56,7 @@ func (w *wrapperTelegramStats) Close() error {
56 56
 		stats.Stats.TelegramDisconnected(w.dc, w.RemoteAddr())
57 57
 	})
58 58
 
59
-	return err
59
+	return err // nolint: wrapcheck
60 60
 }
61 61
 
62 62
 func NewTelegramStats(dc conntypes.DC, parent conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser {

+ 4
- 4
wrappers/stream/stats_traffic.go Visa fil

@@ -17,28 +17,28 @@ func (w *wrapperTrafficStats) Write(p []byte) (int, error) {
17 17
 	n, err := w.parent.Write(p)
18 18
 	stats.Stats.EgressTraffic(n)
19 19
 
20
-	return n, err
20
+	return n, err // nolint: wrapcheck
21 21
 }
22 22
 
23 23
 func (w *wrapperTrafficStats) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
24 24
 	n, err := w.parent.WriteTimeout(p, timeout)
25 25
 	stats.Stats.EgressTraffic(n)
26 26
 
27
-	return n, err
27
+	return n, err // nolint: wrapcheck
28 28
 }
29 29
 
30 30
 func (w *wrapperTrafficStats) Read(p []byte) (int, error) {
31 31
 	n, err := w.parent.Read(p)
32 32
 	stats.Stats.IngressTraffic(n)
33 33
 
34
-	return n, err
34
+	return n, err // nolint: wrapcheck
35 35
 }
36 36
 
37 37
 func (w *wrapperTrafficStats) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
38 38
 	n, err := w.parent.ReadTimeout(p, timeout)
39 39
 	stats.Stats.IngressTraffic(n)
40 40
 
41
-	return n, err
41
+	return n, err // nolint: wrapcheck
42 42
 }
43 43
 
44 44
 func (w *wrapperTrafficStats) Conn() net.Conn {

Laddar…
Avbryt
Spara