Add go-critic

This commit is contained in:
9seconds
2018-07-18 08:53:04 +03:00
parent c1b862c1e9
commit c5f99d17b7
7 changed files with 37 additions and 33 deletions
+1
View File
@@ -13,6 +13,7 @@ script:
- make prepare
- make all
- make lint
- make critic
- make test
cache:
+9 -1
View File
@@ -58,6 +58,10 @@ test: vendor version.go
lint: version.go
@golangci-lint run
.PHONY: critic
critic: version.go
@gocritic check-project "$(ROOT_DIR)"
.PHONY: clean
clean:
@git clean -xfd && \
@@ -69,7 +73,7 @@ docker:
@docker build --pull -t "$(IMAGE_NAME)" "$(ROOT_DIR)"
.PHONY: prepare
prepare: install-dep install-lint
prepare: install-dep install-lint install-critic
.PHONY: install-dep
install-dep:
@@ -79,3 +83,7 @@ install-dep:
install-lint:
@curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh \
| bash -s -- -b $(GOPATH)/bin $(GOLANGCI_LINT_VERSION)
.PHONY: install-critic
install-critic:
@go get -u github.com/go-critic/go-critic/...
+7 -10
View File
@@ -114,13 +114,10 @@ func getAddr(host fmt.Stringer, port uint16) string {
// fetches data from external sources. Parameters passed to this
// function, should come from command line arguments.
func NewConfig(debug, verbose bool, // nolint: gocyclo
bindIP net.IP, bindPort uint16,
publicIPv4 net.IP, PublicIPv4Port uint16,
publicIPv6 net.IP, publicIPv6Port uint16,
statsIP net.IP, statsPort uint16,
secret, adtag string,
statsdIP string, statsdPort uint16, statsdNetwork string, statsdPrefix string,
statsdTagsFormat string, statsdTags map[string]string) (*Config, error) {
bindIP, publicIPv4, publicIPv6, statsIP net.IP,
bindPort, publicIPv4Port, publicIPv6Port, statsPort, statsdPort uint16,
secret, adtag, statsdIP, statsdNetwork, statsdPrefix, statsdTagsFormat string,
statsdTags map[string]string) (*Config, error) {
secureMode := false
if strings.HasPrefix(secret, "dd") && len(secret) == 34 {
secureMode = true
@@ -149,8 +146,8 @@ func NewConfig(debug, verbose bool, // nolint: gocyclo
return nil, errors.Errorf("IP %s is not IPv4", publicIPv4.String())
}
}
if PublicIPv4Port == 0 {
PublicIPv4Port = bindPort
if publicIPv4Port == 0 {
publicIPv4Port = bindPort
}
if publicIPv6 == nil {
@@ -175,7 +172,7 @@ func NewConfig(debug, verbose bool, // nolint: gocyclo
BindIP: bindIP,
BindPort: bindPort,
PublicIPv4: publicIPv4,
PublicIPv4Port: PublicIPv4Port,
PublicIPv4Port: publicIPv4Port,
PublicIPv6: publicIPv6,
PublicIPv6Port: publicIPv6Port,
StatsIP: statsIP,
+3 -3
View File
@@ -42,7 +42,7 @@ func makeTMeURL(values url.Values) string {
}
func makeQRCodeURL(data string) string {
QRURL := url.URL{
qr := url.URL{
Scheme: "https",
Host: "api.qrserver.com",
Path: "v1/create-qr-code",
@@ -52,7 +52,7 @@ func makeQRCodeURL(data string) string {
values.Set("qzone", "4")
values.Set("format", "svg")
values.Set("data", data)
QRURL.RawQuery = values.Encode()
qr.RawQuery = values.Encode()
return QRURL.String()
return qr.String()
}
+8 -10
View File
@@ -129,24 +129,22 @@ func main() {
}
conf, err := config.NewConfig(*debug, *verbose,
*bindIP, *bindPort,
*publicIPv4, *publicIPv4Port,
*publicIPv6, *publicIPv6Port,
*statsIP, *statsPort,
*secret, *adtag,
*statsdIP, *statsdPort, *statsdNetwork, *statsdPrefix,
*statsdTagsFormat, *statsdTags,
*bindIP, *publicIPv4, *publicIPv6, *statsIP,
*bindPort, *publicIPv4Port, *publicIPv6Port, *statsPort, *statsdPort,
*secret, *adtag, *statsdIP, *statsdNetwork, *statsdPrefix, *statsdTagsFormat,
*statsdTags,
)
if err != nil {
usage(err.Error())
}
atom := zap.NewAtomicLevel()
if conf.Debug {
switch {
case conf.Debug:
atom.SetLevel(zapcore.DebugLevel)
} else if conf.Verbose {
case conf.Verbose:
atom.SetLevel(zapcore.InfoLevel)
} else {
default:
atom.SetLevel(zapcore.ErrorLevel)
}
encoderCfg := zap.NewProductionEncoderConfig()
+4 -4
View File
@@ -19,10 +19,10 @@ type HandshakeResponse struct {
func (r *HandshakeResponse) Bytes() []byte {
buf := &bytes.Buffer{}
buf.Write(r.Type[:])
buf.Write(r.Flags[:])
buf.Write(r.SenderPID[:])
buf.Write(r.PeerPID[:])
buf.Write(r.Type)
buf.Write(r.Flags)
buf.Write(r.SenderPID)
buf.Write(r.PeerPID)
return buf.Bytes()
}
+5 -5
View File
@@ -41,9 +41,9 @@ func NewMiddleProxyCipher(conn StreamReadWriteCloser,
func deriveKeys(purpose cipherPurpose, req *rpc.NonceRequest, resp *rpc.NonceResponse,
client, remote *net.TCPAddr, secret []byte) ([]byte, []byte) {
message := bytes.Buffer{}
message.Write(resp.Nonce[:])
message.Write(req.Nonce[:])
message.Write(req.CryptoTS[:])
message.Write(resp.Nonce)
message.Write(req.Nonce)
message.Write(req.CryptoTS)
clientIPv4 := emptyIP[:]
serverIPv4 := emptyIP[:]
@@ -70,13 +70,13 @@ func deriveKeys(purpose cipherPurpose, req *rpc.NonceRequest, resp *rpc.NonceRes
binary.LittleEndian.PutUint16(port[:], uint16(remote.Port))
message.Write(port[:])
message.Write(secret)
message.Write(resp.Nonce[:])
message.Write(resp.Nonce)
if client.IP.To4() == nil {
message.Write(client.IP.To16())
message.Write(remote.IP.To16())
}
message.Write(req.Nonce[:])
message.Write(req.Nonce)
data := message.Bytes()
md5sum := md5.Sum(data[1:]) // nolint: gas