Ver código fonte

Add go-critic

tags/0.11
9seconds 7 anos atrás
pai
commit
c5f99d17b7
7 arquivos alterados com 37 adições e 33 exclusões
  1. 1
    0
      .travis.yml
  2. 9
    1
      Makefile
  3. 7
    10
      config/config.go
  4. 3
    3
      config/urls.go
  5. 8
    10
      main.go
  6. 4
    4
      mtproto/rpc/handshake_response.go
  7. 5
    5
      wrappers/mtproto_cipher.go

+ 1
- 0
.travis.yml Ver arquivo

13
   - make prepare
13
   - make prepare
14
   - make all
14
   - make all
15
   - make lint
15
   - make lint
16
+  - make critic
16
   - make test
17
   - make test
17
 
18
 
18
 cache:
19
 cache:

+ 9
- 1
Makefile Ver arquivo

58
 lint: version.go
58
 lint: version.go
59
 	@golangci-lint run
59
 	@golangci-lint run
60
 
60
 
61
+.PHONY: critic
62
+critic: version.go
63
+	@gocritic check-project "$(ROOT_DIR)"
64
+
61
 .PHONY: clean
65
 .PHONY: clean
62
 clean:
66
 clean:
63
 	@git clean -xfd && \
67
 	@git clean -xfd && \
69
 	@docker build --pull -t "$(IMAGE_NAME)" "$(ROOT_DIR)"
73
 	@docker build --pull -t "$(IMAGE_NAME)" "$(ROOT_DIR)"
70
 
74
 
71
 .PHONY: prepare
75
 .PHONY: prepare
72
-prepare: install-dep install-lint
76
+prepare: install-dep install-lint install-critic
73
 
77
 
74
 .PHONY: install-dep
78
 .PHONY: install-dep
75
 install-dep:
79
 install-dep:
79
 install-lint:
83
 install-lint:
80
 	@curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh \
84
 	@curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh \
81
 		| bash -s -- -b $(GOPATH)/bin $(GOLANGCI_LINT_VERSION)
85
 		| bash -s -- -b $(GOPATH)/bin $(GOLANGCI_LINT_VERSION)
86
+
87
+.PHONY: install-critic
88
+install-critic:
89
+	@go get -u github.com/go-critic/go-critic/...

+ 7
- 10
config/config.go Ver arquivo

114
 // fetches data from external sources. Parameters passed to this
114
 // fetches data from external sources. Parameters passed to this
115
 // function, should come from command line arguments.
115
 // function, should come from command line arguments.
116
 func NewConfig(debug, verbose bool, // nolint: gocyclo
116
 func NewConfig(debug, verbose bool, // nolint: gocyclo
117
-	bindIP net.IP, bindPort uint16,
118
-	publicIPv4 net.IP, PublicIPv4Port uint16,
119
-	publicIPv6 net.IP, publicIPv6Port uint16,
120
-	statsIP net.IP, statsPort uint16,
121
-	secret, adtag string,
122
-	statsdIP string, statsdPort uint16, statsdNetwork string, statsdPrefix string,
123
-	statsdTagsFormat string, statsdTags map[string]string) (*Config, error) {
117
+	bindIP, publicIPv4, publicIPv6, statsIP net.IP,
118
+	bindPort, publicIPv4Port, publicIPv6Port, statsPort, statsdPort uint16,
119
+	secret, adtag, statsdIP, statsdNetwork, statsdPrefix, statsdTagsFormat string,
120
+	statsdTags map[string]string) (*Config, error) {
124
 	secureMode := false
121
 	secureMode := false
125
 	if strings.HasPrefix(secret, "dd") && len(secret) == 34 {
122
 	if strings.HasPrefix(secret, "dd") && len(secret) == 34 {
126
 		secureMode = true
123
 		secureMode = true
149
 			return nil, errors.Errorf("IP %s is not IPv4", publicIPv4.String())
146
 			return nil, errors.Errorf("IP %s is not IPv4", publicIPv4.String())
150
 		}
147
 		}
151
 	}
148
 	}
152
-	if PublicIPv4Port == 0 {
153
-		PublicIPv4Port = bindPort
149
+	if publicIPv4Port == 0 {
150
+		publicIPv4Port = bindPort
154
 	}
151
 	}
155
 
152
 
156
 	if publicIPv6 == nil {
153
 	if publicIPv6 == nil {
175
 		BindIP:         bindIP,
172
 		BindIP:         bindIP,
176
 		BindPort:       bindPort,
173
 		BindPort:       bindPort,
177
 		PublicIPv4:     publicIPv4,
174
 		PublicIPv4:     publicIPv4,
178
-		PublicIPv4Port: PublicIPv4Port,
175
+		PublicIPv4Port: publicIPv4Port,
179
 		PublicIPv6:     publicIPv6,
176
 		PublicIPv6:     publicIPv6,
180
 		PublicIPv6Port: publicIPv6Port,
177
 		PublicIPv6Port: publicIPv6Port,
181
 		StatsIP:        statsIP,
178
 		StatsIP:        statsIP,

+ 3
- 3
config/urls.go Ver arquivo

42
 }
42
 }
43
 
43
 
44
 func makeQRCodeURL(data string) string {
44
 func makeQRCodeURL(data string) string {
45
-	QRURL := url.URL{
45
+	qr := url.URL{
46
 		Scheme: "https",
46
 		Scheme: "https",
47
 		Host:   "api.qrserver.com",
47
 		Host:   "api.qrserver.com",
48
 		Path:   "v1/create-qr-code",
48
 		Path:   "v1/create-qr-code",
52
 	values.Set("qzone", "4")
52
 	values.Set("qzone", "4")
53
 	values.Set("format", "svg")
53
 	values.Set("format", "svg")
54
 	values.Set("data", data)
54
 	values.Set("data", data)
55
-	QRURL.RawQuery = values.Encode()
55
+	qr.RawQuery = values.Encode()
56
 
56
 
57
-	return QRURL.String()
57
+	return qr.String()
58
 }
58
 }

+ 8
- 10
main.go Ver arquivo

129
 	}
129
 	}
130
 
130
 
131
 	conf, err := config.NewConfig(*debug, *verbose,
131
 	conf, err := config.NewConfig(*debug, *verbose,
132
-		*bindIP, *bindPort,
133
-		*publicIPv4, *publicIPv4Port,
134
-		*publicIPv6, *publicIPv6Port,
135
-		*statsIP, *statsPort,
136
-		*secret, *adtag,
137
-		*statsdIP, *statsdPort, *statsdNetwork, *statsdPrefix,
138
-		*statsdTagsFormat, *statsdTags,
132
+		*bindIP, *publicIPv4, *publicIPv6, *statsIP,
133
+		*bindPort, *publicIPv4Port, *publicIPv6Port, *statsPort, *statsdPort,
134
+		*secret, *adtag, *statsdIP, *statsdNetwork, *statsdPrefix, *statsdTagsFormat,
135
+		*statsdTags,
139
 	)
136
 	)
140
 	if err != nil {
137
 	if err != nil {
141
 		usage(err.Error())
138
 		usage(err.Error())
142
 	}
139
 	}
143
 
140
 
144
 	atom := zap.NewAtomicLevel()
141
 	atom := zap.NewAtomicLevel()
145
-	if conf.Debug {
142
+	switch {
143
+	case conf.Debug:
146
 		atom.SetLevel(zapcore.DebugLevel)
144
 		atom.SetLevel(zapcore.DebugLevel)
147
-	} else if conf.Verbose {
145
+	case conf.Verbose:
148
 		atom.SetLevel(zapcore.InfoLevel)
146
 		atom.SetLevel(zapcore.InfoLevel)
149
-	} else {
147
+	default:
150
 		atom.SetLevel(zapcore.ErrorLevel)
148
 		atom.SetLevel(zapcore.ErrorLevel)
151
 	}
149
 	}
152
 	encoderCfg := zap.NewProductionEncoderConfig()
150
 	encoderCfg := zap.NewProductionEncoderConfig()

+ 4
- 4
mtproto/rpc/handshake_response.go Ver arquivo

19
 func (r *HandshakeResponse) Bytes() []byte {
19
 func (r *HandshakeResponse) Bytes() []byte {
20
 	buf := &bytes.Buffer{}
20
 	buf := &bytes.Buffer{}
21
 
21
 
22
-	buf.Write(r.Type[:])
23
-	buf.Write(r.Flags[:])
24
-	buf.Write(r.SenderPID[:])
25
-	buf.Write(r.PeerPID[:])
22
+	buf.Write(r.Type)
23
+	buf.Write(r.Flags)
24
+	buf.Write(r.SenderPID)
25
+	buf.Write(r.PeerPID)
26
 
26
 
27
 	return buf.Bytes()
27
 	return buf.Bytes()
28
 }
28
 }

+ 5
- 5
wrappers/mtproto_cipher.go Ver arquivo

41
 func deriveKeys(purpose cipherPurpose, req *rpc.NonceRequest, resp *rpc.NonceResponse,
41
 func deriveKeys(purpose cipherPurpose, req *rpc.NonceRequest, resp *rpc.NonceResponse,
42
 	client, remote *net.TCPAddr, secret []byte) ([]byte, []byte) {
42
 	client, remote *net.TCPAddr, secret []byte) ([]byte, []byte) {
43
 	message := bytes.Buffer{}
43
 	message := bytes.Buffer{}
44
-	message.Write(resp.Nonce[:])
45
-	message.Write(req.Nonce[:])
46
-	message.Write(req.CryptoTS[:])
44
+	message.Write(resp.Nonce)
45
+	message.Write(req.Nonce)
46
+	message.Write(req.CryptoTS)
47
 
47
 
48
 	clientIPv4 := emptyIP[:]
48
 	clientIPv4 := emptyIP[:]
49
 	serverIPv4 := emptyIP[:]
49
 	serverIPv4 := emptyIP[:]
70
 	binary.LittleEndian.PutUint16(port[:], uint16(remote.Port))
70
 	binary.LittleEndian.PutUint16(port[:], uint16(remote.Port))
71
 	message.Write(port[:])
71
 	message.Write(port[:])
72
 	message.Write(secret)
72
 	message.Write(secret)
73
-	message.Write(resp.Nonce[:])
73
+	message.Write(resp.Nonce)
74
 
74
 
75
 	if client.IP.To4() == nil {
75
 	if client.IP.To4() == nil {
76
 		message.Write(client.IP.To16())
76
 		message.Write(client.IP.To16())
77
 		message.Write(remote.IP.To16())
77
 		message.Write(remote.IP.To16())
78
 	}
78
 	}
79
-	message.Write(req.Nonce[:])
79
+	message.Write(req.Nonce)
80
 
80
 
81
 	data := message.Bytes()
81
 	data := message.Bytes()
82
 	md5sum := md5.Sum(data[1:]) // nolint: gas
82
 	md5sum := md5.Sum(data[1:]) // nolint: gas

Carregando…
Cancelar
Salvar