Explorar el Código

Update golangci-linter

tags/v1.0.8
9seconds hace 5 años
padre
commit
33b1a5426c

+ 1
- 1
.golangci.toml Ver fichero

10
 
10
 
11
 [linters]
11
 [linters]
12
 enable-all = true
12
 enable-all = true
13
-disable = ["gochecknoglobals", "gas", "gomnd", "goerr113"]
13
+disable = ["gochecknoglobals", "gas", "gomnd", "goerr113", "exhaustivestruct"]

+ 1
- 1
Makefile Ver fichero

4
 
4
 
5
 CC_BINARIES  := $(shell bash -c "echo -n $(APP_NAME)-{linux,freebsd,openbsd}-{386,amd64} $(APP_NAME)-linux-{arm,arm64}")
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
 VERSION_GO         := $(shell go version)
9
 VERSION_GO         := $(shell go version)
10
 VERSION_DATE       := $(shell date -Ru)
10
 VERSION_DATE       := $(shell date -Ru)

+ 1
- 1
cli/proxy.go Ver fichero

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

+ 2
- 2
cli/utils.go Ver fichero

9
 
9
 
10
 func Fatal(arg interface{}) {
10
 func Fatal(arg interface{}) {
11
 	if value, ok := arg.(error); ok {
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
 	PrintStderr(arg)
15
 	PrintStderr(arg)
21
 }
21
 }
22
 
22
 
23
 func PrintStdout(args ...interface{}) {
23
 func PrintStdout(args ...interface{}) {
24
-	fmt.Println(args...)
24
+	fmt.Println(args...) // nolint: forbidigo
25
 }
25
 }
26
 
26
 
27
 func PrintJSONStderr(data interface{}) {
27
 func PrintJSONStderr(data interface{}) {

+ 1
- 1
config/config.go Ver fichero

160
 
160
 
161
 var C = Config{}
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
 	for _, opt := range options {
164
 	for _, opt := range options {
165
 		switch opt.Option {
165
 		switch opt.Option {
166
 		case OptionTypeDebug:
166
 		case OptionTypeDebug:

+ 2
- 2
faketls/client_protocol.go Ver fichero

52
 
52
 
53
 	conn, err := c.ClientProtocol.Handshake(conn)
53
 	conn, err := c.ClientProtocol.Handshake(conn)
54
 	if err != nil {
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
 func (c *ClientProtocol) tlsHandshake(conn io.ReadWriter) error {
61
 func (c *ClientProtocol) tlsHandshake(conn io.ReadWriter) error {

+ 1
- 1
hub/connection.go Ver fichero

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

+ 1
- 1
mtproto/protocol.go Ver fichero

51
 	}
51
 	}
52
 
52
 
53
 	if err := conn.Write(rpcNonceReq.Bytes()); err != nil {
53
 	if err := conn.Write(rpcNonceReq.Bytes()); err != nil {
54
-		return nil, err
54
+		return nil, err // nolint: wrapcheck
55
 	}
55
 	}
56
 
56
 
57
 	return rpcNonceReq, nil
57
 	return rpcNonceReq, nil

+ 1
- 1
proxy/direct.go Ver fichero

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

+ 5
- 4
stats/stats_statsd.go Ver fichero

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

+ 1
- 1
telegram/api/api.go Ver fichero

40
 		return nil, fmt.Errorf("cannot perform a request: %w", err)
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 Ver fichero

20
 type CipherSuiteType uint8
20
 type CipherSuiteType uint8
21
 
21
 
22
 const (
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
 func (c CipherSuiteType) Bytes() []byte {
28
 func (c CipherSuiteType) Bytes() []byte {
69
 	Version12Bytes = []byte{0x03, 0x03}
69
 	Version12Bytes = []byte{0x03, 0x03}
70
 	Version13Bytes = []byte{0x03, 0x04}
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
 type Byter interface {
77
 type Byter interface {

+ 1
- 1
utils/read_full.go Ver fichero

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

+ 2
- 2
wrappers/packet/mtproto_frame.go Ver fichero

40
 	writeSeqNo int32
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
 	buf := &bytes.Buffer{}
44
 	buf := &bytes.Buffer{}
45
 
45
 
46
 	sum := crc32.NewIEEE()
46
 	sum := crc32.NewIEEE()
132
 
132
 
133
 	_, err := w.parent.Write(buf.Bytes())
133
 	_, err := w.parent.Write(buf.Bytes())
134
 
134
 
135
-	return err
135
+	return err // nolint: wrapcheck
136
 }
136
 }
137
 
137
 
138
 func (w *wrapperMtprotoFrame) Close() error {
138
 func (w *wrapperMtprotoFrame) Close() error {

+ 2
- 2
wrappers/rwc/ping.go Ver fichero

20
 		}
20
 		}
21
 	}
21
 	}
22
 
22
 
23
-	return n, err
23
+	return n, err // nolint: wrapcheck
24
 }
24
 }
25
 
25
 
26
 func (w *wrapperPing) Write(p []byte) (int, error) {
26
 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
 func (w *wrapperPing) Close() error {
38
 func (w *wrapperPing) Close() error {

+ 2
- 2
wrappers/stream/conn.go Ver fichero

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

+ 1
- 1
wrappers/stream/faketls.go Ver fichero

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

+ 1
- 1
wrappers/stream/obfuscated2.go Ver fichero

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

+ 7
- 6
wrappers/stream/rewind.go Ver fichero

2
 
2
 
3
 import (
3
 import (
4
 	"bytes"
4
 	"bytes"
5
+	"errors"
5
 	"io"
6
 	"io"
6
 	"net"
7
 	"net"
7
 	"sync"
8
 	"sync"
36
 	defer w.mutex.Unlock()
37
 	defer w.mutex.Unlock()
37
 
38
 
38
 	if w.rewinded {
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
 		w.buf.Write(p[:n])
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
 func (w *wrapperRewind) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
54
 func (w *wrapperRewind) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
55
 	defer w.mutex.Unlock()
56
 	defer w.mutex.Unlock()
56
 
57
 
57
 	if w.rewinded {
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
 		w.buf.Write(p[:n])
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
 func (w *wrapperRewind) Conn() net.Conn {
73
 func (w *wrapperRewind) Conn() net.Conn {

+ 1
- 1
wrappers/stream/stats_telegram.go Ver fichero

56
 		stats.Stats.TelegramDisconnected(w.dc, w.RemoteAddr())
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
 func NewTelegramStats(dc conntypes.DC, parent conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser {
62
 func NewTelegramStats(dc conntypes.DC, parent conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser {

+ 4
- 4
wrappers/stream/stats_traffic.go Ver fichero

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

Loading…
Cancelar
Guardar