Merge pull request #174 from 9seconds/linter

Update golangci-linter
This commit is contained in:
Sergey Arkhipov
2021-03-02 16:18:05 +03:00
committed by GitHub
21 changed files with 44 additions and 42 deletions
+1 -1
View File
@@ -10,4 +10,4 @@ format = "colored-line-number"
[linters]
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}")
GOLANGCI_LINT_VERSION := v1.31.0
GOLANGCI_LINT_VERSION := v1.37.1
VERSION_GO := $(shell go version)
VERSION_DATE := $(shell date -Ru)
+1 -1
View File
@@ -19,7 +19,7 @@ import (
"go.uber.org/zap/zapcore"
)
func Proxy() error { // nolint: funlen
func Proxy() error { // nolint: funlen,cyclop
ctx := utils.GetSignalContext()
atom := zap.NewAtomicLevel()
+2 -2
View File
@@ -9,7 +9,7 @@ import (
func Fatal(arg interface{}) {
if value, ok := arg.(error); ok {
arg = fmt.Errorf("fatal error: %+v", value)
arg = fmt.Errorf("fatal error: %+v", value) // nolint: errorlint
}
PrintStderr(arg)
@@ -21,7 +21,7 @@ func PrintStderr(args ...interface{}) {
}
func PrintStdout(args ...interface{}) {
fmt.Println(args...)
fmt.Println(args...) // nolint: forbidigo
}
func PrintJSONStderr(data interface{}) {
+1 -1
View File
@@ -160,7 +160,7 @@ type Opt struct {
var C = Config{}
func Init(options ...Opt) error { // nolint: gocyclo, funlen
func Init(options ...Opt) error { // nolint: gocyclo, funlen, cyclop
for _, opt := range options {
switch opt.Option {
case OptionTypeDebug:
+2 -2
View File
@@ -52,10 +52,10 @@ func (c *ClientProtocol) Handshake(socket conntypes.StreamReadWriteCloser) (conn
conn, err := c.ClientProtocol.Handshake(conn)
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 {
+1 -1
View File
@@ -30,7 +30,7 @@ type connection struct {
channelConnDetach chan conntypes.ConnID
}
func (c *connection) run() {
func (c *connection) run() { // nolint: cyclop
defer c.Close()
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 {
return nil, err
return nil, err // nolint: wrapcheck
}
return rpcNonceReq, nil
+1 -1
View File
@@ -15,7 +15,7 @@ const directPipeBufferSize = 1024
func directConnection(request *protocol.TelegramRequest) error {
telegramConnRaw, err := obfuscated2.TelegramProtocol(request)
if err != nil {
return err
return err // nolint: wrapcheck
}
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) {
s.seenMutex.RLock()
_, ok := s.seen[key]
s.seenMutex.RUnlock()
if _, ok := s.seen[key]; ok {
s.seenMutex.RUnlock()
if ok {
return
} else { // nolint: golint,revive
s.seenMutex.RUnlock()
}
s.seenMutex.Lock()
defer s.seenMutex.Unlock()
if _, ok = s.seen[key]; !ok {
if _, ok := s.seen[key]; !ok {
s.seen[key] = struct{}{}
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 resp.Body, err
return resp.Body, err // nolint: wrapcheck
}
+6 -6
View File
@@ -20,9 +20,9 @@ const (
type CipherSuiteType uint8
const (
CipherSuiteType_TLS_AES_128_GCM_SHA256 CipherSuiteType = iota // nolint: stylecheck,golint
CipherSuiteType_TLS_AES_256_GCM_SHA384 // nolint: stylecheck,golint
CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256 // nolint: stylecheck,golint
CipherSuiteType_TLS_AES_128_GCM_SHA256 CipherSuiteType = iota // nolint: stylecheck,golint,revive
CipherSuiteType_TLS_AES_256_GCM_SHA384 // nolint: stylecheck,golint,revive
CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256 // nolint: stylecheck,golint,revive
)
func (c CipherSuiteType) Bytes() []byte {
@@ -69,9 +69,9 @@ var (
Version12Bytes = []byte{0x03, 0x03}
Version13Bytes = []byte{0x03, 0x04}
CipherSuiteType_TLS_AES_128_GCM_SHA256_Bytes = []byte{0x13, 0x01} // nolint: stylecheck,golint
CipherSuiteType_TLS_AES_256_GCM_SHA384_Bytes = []byte{0x13, 0x02} // nolint: stylecheck,golint
CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes = []byte{0x13, 0x03} // 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,revive
CipherSuiteType_TLS_CHACHA20_POLY1305_SHA256_Bytes = []byte{0x13, 0x03} // nolint: stylecheck,golint,revive
)
type Byter interface {
+1 -1
View File
@@ -11,7 +11,7 @@ func ReadFull(src io.Reader) (rv []byte, err error) {
for n == len(buf) {
n, err = src.Read(buf)
if err != nil {
return nil, err
return nil, err // nolint: wrapcheck
}
rv = append(rv, buf[:n]...)
+2 -2
View File
@@ -40,7 +40,7 @@ type wrapperMtprotoFrame struct {
writeSeqNo int32
}
func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funlen
func (w *wrapperMtprotoFrame) Read() (conntypes.Packet, error) { // nolint: funlen, cyclop
buf := &bytes.Buffer{}
sum := crc32.NewIEEE()
@@ -132,7 +132,7 @@ func (w *wrapperMtprotoFrame) Write(p conntypes.Packet) error {
_, err := w.parent.Write(buf.Bytes())
return err
return err // nolint: wrapcheck
}
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) {
@@ -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 {
+2 -2
View File
@@ -43,7 +43,7 @@ func (w *wrapperConn) Write(p []byte) (int, error) {
w.Close()
}
return n, err
return n, err // nolint: wrapcheck
}
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()
}
return n, err
return n, err // nolint: wrapcheck
}
func (w *wrapperConn) Close() error {
+1 -1
View File
@@ -85,7 +85,7 @@ func NewFakeTLS(socket conntypes.StreamReadWriteCloser) conntypes.StreamReadWrit
for {
rec, err := tlstypes.ReadRecord(faketls.parent)
if err != nil {
return nil, err
return nil, err // nolint: wrapcheck
}
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) {
n, err := w.parent.Read(p)
if err != nil {
return n, err
return n, err // nolint: wrapcheck
}
w.decryptor.XORKeyStream(p, p[:n])
+7 -6
View File
@@ -2,6 +2,7 @@ package stream
import (
"bytes"
"errors"
"io"
"net"
"sync"
@@ -36,8 +37,8 @@ func (w *wrapperRewind) Read(p []byte) (int, error) {
defer w.mutex.Unlock()
if w.rewinded {
if n, err := w.buf.Read(p); err != io.EOF {
return n, err
if n, err := w.buf.Read(p); errors.Is(err, io.EOF) {
return n, err // nolint: wrapcheck
}
}
@@ -47,7 +48,7 @@ func (w *wrapperRewind) Read(p []byte) (int, error) {
w.buf.Write(p[:n])
}
return n, err
return n, err // nolint: wrapcheck
}
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()
if w.rewinded {
if n, err := w.buf.Read(p); err != io.EOF {
return n, err
if n, err := w.buf.Read(p); errors.Is(err, io.EOF) {
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])
}
return n, err
return n, err // nolint: wrapcheck
}
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())
})
return err
return err // nolint: wrapcheck
}
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)
stats.Stats.EgressTraffic(n)
return n, err
return n, err // nolint: wrapcheck
}
func (w *wrapperTrafficStats) WriteTimeout(p []byte, timeout time.Duration) (int, error) {
n, err := w.parent.WriteTimeout(p, timeout)
stats.Stats.EgressTraffic(n)
return n, err
return n, err // nolint: wrapcheck
}
func (w *wrapperTrafficStats) Read(p []byte) (int, error) {
n, err := w.parent.Read(p)
stats.Stats.IngressTraffic(n)
return n, err
return n, err // nolint: wrapcheck
}
func (w *wrapperTrafficStats) ReadTimeout(p []byte, timeout time.Duration) (int, error) {
n, err := w.parent.ReadTimeout(p, timeout)
stats.Stats.IngressTraffic(n)
return n, err
return n, err // nolint: wrapcheck
}
func (w *wrapperTrafficStats) Conn() net.Conn {