Update golangci-linter

This commit is contained in:
9seconds
2021-02-26 00:52:09 +03:00
parent 91197c0334
commit 33b1a5426c
21 changed files with 44 additions and 42 deletions
+1 -1
View File
@@ -10,4 +10,4 @@ format = "colored-line-number"
[linters] [linters]
enable-all = true enable-all = true
disable = ["gochecknoglobals", "gas", "gomnd", "goerr113"] disable = ["gochecknoglobals", "gas", "gomnd", "goerr113", "exhaustivestruct"]
+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}") CC_BINARIES := $(shell bash -c "echo -n $(APP_NAME)-{linux,freebsd,openbsd}-{386,amd64} $(APP_NAME)-linux-{arm,arm64}")
GOLANGCI_LINT_VERSION := v1.31.0 GOLANGCI_LINT_VERSION := v1.37.1
VERSION_GO := $(shell go version) VERSION_GO := $(shell go version)
VERSION_DATE := $(shell date -Ru) VERSION_DATE := $(shell date -Ru)
+1 -1
View File
@@ -19,7 +19,7 @@ import (
"go.uber.org/zap/zapcore" "go.uber.org/zap/zapcore"
) )
func Proxy() error { // nolint: funlen func Proxy() error { // nolint: funlen,cyclop
ctx := utils.GetSignalContext() ctx := utils.GetSignalContext()
atom := zap.NewAtomicLevel() atom := zap.NewAtomicLevel()
+2 -2
View File
@@ -9,7 +9,7 @@ import (
func Fatal(arg interface{}) { func Fatal(arg interface{}) {
if value, ok := arg.(error); ok { if value, ok := arg.(error); ok {
arg = fmt.Errorf("fatal error: %+v", value) arg = fmt.Errorf("fatal error: %+v", value) // nolint: errorlint
} }
PrintStderr(arg) PrintStderr(arg)
@@ -21,7 +21,7 @@ func PrintStderr(args ...interface{}) {
} }
func PrintStdout(args ...interface{}) { func PrintStdout(args ...interface{}) {
fmt.Println(args...) fmt.Println(args...) // nolint: forbidigo
} }
func PrintJSONStderr(data interface{}) { func PrintJSONStderr(data interface{}) {
+1 -1
View File
@@ -160,7 +160,7 @@ type Opt struct {
var C = Config{} var C = Config{}
func Init(options ...Opt) error { // nolint: gocyclo, funlen func Init(options ...Opt) error { // nolint: gocyclo, funlen, cyclop
for _, opt := range options { for _, opt := range options {
switch opt.Option { switch opt.Option {
case OptionTypeDebug: case OptionTypeDebug:
+2 -2
View File
@@ -52,10 +52,10 @@ func (c *ClientProtocol) Handshake(socket conntypes.StreamReadWriteCloser) (conn
conn, err := c.ClientProtocol.Handshake(conn) conn, err := c.ClientProtocol.Handshake(conn)
if err != nil { if err != nil {
return nil, err return nil, err // nolint: wrapcheck
} }
return conn, err return conn, err // nolint: wrapcheck
} }
func (c *ClientProtocol) tlsHandshake(conn io.ReadWriter) error { func (c *ClientProtocol) tlsHandshake(conn io.ReadWriter) error {
+1 -1
View File
@@ -30,7 +30,7 @@ type connection struct {
channelConnDetach chan conntypes.ConnID channelConnDetach chan conntypes.ConnID
} }
func (c *connection) run() { func (c *connection) run() { // nolint: cyclop
defer c.Close() defer c.Close()
ttl := time.NewTimer(connectionTTL) ttl := time.NewTimer(connectionTTL)
+1 -1
View File
@@ -51,7 +51,7 @@ func doRPCNonceRequest(conn conntypes.BasePacketWriter) (*rpc.NonceRequest, erro
} }
if err := conn.Write(rpcNonceReq.Bytes()); err != nil { if err := conn.Write(rpcNonceReq.Bytes()); err != nil {
return nil, err return nil, err // nolint: wrapcheck
} }
return rpcNonceReq, nil return rpcNonceReq, nil
+1 -1
View File
@@ -15,7 +15,7 @@ const directPipeBufferSize = 1024
func directConnection(request *protocol.TelegramRequest) error { func directConnection(request *protocol.TelegramRequest) error {
telegramConnRaw, err := obfuscated2.TelegramProtocol(request) telegramConnRaw, err := obfuscated2.TelegramProtocol(request)
if err != nil { if err != nil {
return err return err // nolint: wrapcheck
} }
telegramConn := telegramConnRaw.(conntypes.StreamReadWriteCloser) telegramConn := telegramConnRaw.(conntypes.StreamReadWriteCloser)
+5 -4
View File
@@ -168,17 +168,18 @@ func (s *statsStatsd) prepareVals(metric string, tags []*statsStatsdTag) (string
func (s *statsStatsd) initGauge(metric, key string, tags []statsd.Tag) { func (s *statsStatsd) initGauge(metric, key string, tags []statsd.Tag) {
s.seenMutex.RLock() s.seenMutex.RLock()
_, ok := s.seen[key] if _, ok := s.seen[key]; ok {
s.seenMutex.RUnlock() s.seenMutex.RUnlock()
if ok {
return return
} else { // nolint: golint,revive
s.seenMutex.RUnlock()
} }
s.seenMutex.Lock() s.seenMutex.Lock()
defer s.seenMutex.Unlock() defer s.seenMutex.Unlock()
if _, ok = s.seen[key]; !ok { if _, ok := s.seen[key]; !ok {
s.seen[key] = struct{}{} s.seen[key] = struct{}{}
s.client.Gauge(metric, 0, tags...) s.client.Gauge(metric, 0, tags...)
} }
+1 -1
View File
@@ -40,5 +40,5 @@ func request(url string) (io.ReadCloser, error) {
return nil, fmt.Errorf("cannot perform a request: %w", err) return nil, fmt.Errorf("cannot perform a request: %w", err)
} }
return resp.Body, err return resp.Body, err // nolint: wrapcheck
} }
+6 -6
View File
@@ -20,9 +20,9 @@ const (
type CipherSuiteType uint8 type CipherSuiteType uint8
const ( const (
CipherSuiteType_TLS_AES_128_GCM_SHA256 CipherSuiteType = iota // nolint: stylecheck,golint CipherSuiteType_TLS_AES_128_GCM_SHA256 CipherSuiteType = iota // nolint: stylecheck,golint,revive
CipherSuiteType_TLS_AES_256_GCM_SHA384 // nolint: stylecheck,golint CipherSuiteType_TLS_AES_256_GCM_SHA384 // nolint: stylecheck,golint,revive
CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256 // nolint: stylecheck,golint CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256 // nolint: stylecheck,golint,revive
) )
func (c CipherSuiteType) Bytes() []byte { func (c CipherSuiteType) Bytes() []byte {
@@ -69,9 +69,9 @@ var (
Version12Bytes = []byte{0x03, 0x03} Version12Bytes = []byte{0x03, 0x03}
Version13Bytes = []byte{0x03, 0x04} Version13Bytes = []byte{0x03, 0x04}
CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes = []byte{0x13, 0x01} // nolint: stylecheck,golint CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes = []byte{0x13, 0x01} // nolint: stylecheck,golint,revive
CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes = []byte{0x13, 0x02} // nolint: stylecheck,golint CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes = []byte{0x13, 0x02} // nolint: stylecheck,golint,revive
CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes = []byte{0x13, 0x03} // nolint: stylecheck,golint CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes = []byte{0x13, 0x03} // nolint: stylecheck,golint,revive
) )
type Byter interface { type Byter interface {
+1 -1
View File
@@ -11,7 +11,7 @@ func ReadFull(src io.Reader) (rv []byte, err error) {
for n == len(buf) { for n == len(buf) {
n, err = src.Read(buf) n, err = src.Read(buf)
if err != nil { if err != nil {
return nil, err return nil, err // nolint: wrapcheck
} }
rv = append(rv, buf[:n]...) rv = append(rv, buf[:n]...)
+2 -2
View File
@@ -40,7 +40,7 @@ type wrapperMtprotoFrame struct {
writeSeqNo int32 writeSeqNo int32
} }
func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funlen func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funlen, cyclop
buf := &bytes.Buffer{} buf := &bytes.Buffer{}
sum := crc32.NewIEEE() sum := crc32.NewIEEE()
@@ -132,7 +132,7 @@ func (w *wrapperMtprotoFrame) Write(p conntypes.Packet) error {
_, err := w.parent.Write(buf.Bytes()) _, err := w.parent.Write(buf.Bytes())
return err return err // nolint: wrapcheck
} }
func (w *wrapperMtprotoFrame) Close() error { func (w *wrapperMtprotoFrame) Close() error {
+2 -2
View File
@@ -20,7 +20,7 @@ func (w *wrapperPing) Read(p []byte) (int, error) {
} }
} }
return n, err return n, err // nolint: wrapcheck
} }
func (w *wrapperPing) Write(p []byte) (int, error) { func (w *wrapperPing) Write(p []byte) (int, error) {
@@ -32,7 +32,7 @@ func (w *wrapperPing) Write(p []byte) (int, error) {
} }
} }
return n, err return n, err // nolint: wrapcheck
} }
func (w *wrapperPing) Close() error { func (w *wrapperPing) Close() error {
+2 -2
View File
@@ -43,7 +43,7 @@ func (w *wrapperConn) Write(p []byte) (int, error) {
w.Close() w.Close()
} }
return n, err return n, err // nolint: wrapcheck
} }
func (w *wrapperConn) ReadTimeout(p []byte, timeout time.Duration) (int, error) { func (w *wrapperConn) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
@@ -64,7 +64,7 @@ func (w *wrapperConn) Read(p []byte) (int, error) {
w.Close() w.Close()
} }
return n, err return n, err // nolint: wrapcheck
} }
func (w *wrapperConn) Close() error { func (w *wrapperConn) Close() error {
+1 -1
View File
@@ -85,7 +85,7 @@ func NewFakeTLS(socket conntypes.StreamReadWriteCloser) conntypes.StreamReadWrit
for { for {
rec, err := tlstypes.ReadRecord(faketls.parent) rec, err := tlstypes.ReadRecord(faketls.parent)
if err != nil { if err != nil {
return nil, err return nil, err // nolint: wrapcheck
} }
switch rec.Type { switch rec.Type {
+1 -1
View File
@@ -31,7 +31,7 @@ func (w *wrapperObfuscated2) ReadTimeout(p []byte, timeout time.Duration) (int,
func (w *wrapperObfuscated2) Read(p []byte) (int, error) { func (w *wrapperObfuscated2) Read(p []byte) (int, error) {
n, err := w.parent.Read(p) n, err := w.parent.Read(p)
if err != nil { if err != nil {
return n, err return n, err // nolint: wrapcheck
} }
w.decryptor.XORKeyStream(p, p[:n]) w.decryptor.XORKeyStream(p, p[:n])
+7 -6
View File
@@ -2,6 +2,7 @@ package stream
import ( import (
"bytes" "bytes"
"errors"
"io" "io"
"net" "net"
"sync" "sync"
@@ -36,8 +37,8 @@ func (w *wrapperRewind) Read(p []byte) (int, error) {
defer w.mutex.Unlock() defer w.mutex.Unlock()
if w.rewinded { if w.rewinded {
if n, err := w.buf.Read(p); err != io.EOF { if n, err := w.buf.Read(p); errors.Is(err, io.EOF) {
return n, err return n, err // nolint: wrapcheck
} }
} }
@@ -47,7 +48,7 @@ func (w *wrapperRewind) Read(p []byte) (int, error) {
w.buf.Write(p[:n]) w.buf.Write(p[:n])
} }
return n, err return n, err // nolint: wrapcheck
} }
func (w *wrapperRewind) ReadTimeout(p []byte, timeout time.Duration) (int, error) { 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
defer w.mutex.Unlock() defer w.mutex.Unlock()
if w.rewinded { if w.rewinded {
if n, err := w.buf.Read(p); err != io.EOF { if n, err := w.buf.Read(p); errors.Is(err, io.EOF) {
return n, err return n, err // nolint: wrapcheck
} }
} }
@@ -66,7 +67,7 @@ func (w *wrapperRewind) ReadTimeout(p []byte, timeout time.Duration) (int, error
w.buf.Write(p[:n]) w.buf.Write(p[:n])
} }
return n, err return n, err // nolint: wrapcheck
} }
func (w *wrapperRewind) Conn() net.Conn { func (w *wrapperRewind) Conn() net.Conn {
+1 -1
View File
@@ -56,7 +56,7 @@ func (w *wrapperTelegramStats) Close() error {
stats.Stats.TelegramDisconnected(w.dc, w.RemoteAddr()) stats.Stats.TelegramDisconnected(w.dc, w.RemoteAddr())
}) })
return err return err // nolint: wrapcheck
} }
func NewTelegramStats(dc conntypes.DC, parent conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser { func NewTelegramStats(dc conntypes.DC, parent conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser {
+4 -4
View File
@@ -17,28 +17,28 @@ func (w *wrapperTrafficStats) Write(p []byte) (int, error) {
n, err := w.parent.Write(p) n, err := w.parent.Write(p)
stats.Stats.EgressTraffic(n) stats.Stats.EgressTraffic(n)
return n, err return n, err // nolint: wrapcheck
} }
func (w *wrapperTrafficStats) WriteTimeout(p []byte, timeout time.Duration) (int, error) { func (w *wrapperTrafficStats) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
n, err := w.parent.WriteTimeout(p, timeout) n, err := w.parent.WriteTimeout(p, timeout)
stats.Stats.EgressTraffic(n) stats.Stats.EgressTraffic(n)
return n, err return n, err // nolint: wrapcheck
} }
func (w *wrapperTrafficStats) Read(p []byte) (int, error) { func (w *wrapperTrafficStats) Read(p []byte) (int, error) {
n, err := w.parent.Read(p) n, err := w.parent.Read(p)
stats.Stats.IngressTraffic(n) stats.Stats.IngressTraffic(n)
return n, err return n, err // nolint: wrapcheck
} }
func (w *wrapperTrafficStats) ReadTimeout(p []byte, timeout time.Duration) (int, error) { func (w *wrapperTrafficStats) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
n, err := w.parent.ReadTimeout(p, timeout) n, err := w.parent.ReadTimeout(p, timeout)
stats.Stats.IngressTraffic(n) stats.Stats.IngressTraffic(n)
return n, err return n, err // nolint: wrapcheck
} }
func (w *wrapperTrafficStats) Conn() net.Conn { func (w *wrapperTrafficStats) Conn() net.Conn {