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