mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 14:04:02 +03:00
Update golangci-lint
This commit is contained in:
+11
-1
@@ -9,4 +9,14 @@ format = "colored-line-number"
|
|||||||
|
|
||||||
[linters]
|
[linters]
|
||||||
enable-all = true
|
enable-all = true
|
||||||
disable = ["thelper", "ireturn", "varnamelen", "gochecknoglobals", "gas", "goerr113", "exhaustivestruct", "containedctx"]
|
disable = [
|
||||||
|
"containedctx",
|
||||||
|
"exhaustivestruct",
|
||||||
|
"exhaustruct",
|
||||||
|
"gas",
|
||||||
|
"gochecknoglobals",
|
||||||
|
"goerr113",
|
||||||
|
"ireturn",
|
||||||
|
"thelper",
|
||||||
|
"varnamelen",
|
||||||
|
]
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
|||||||
IMAGE_NAME := mtg
|
IMAGE_NAME := mtg
|
||||||
APP_NAME := $(IMAGE_NAME)
|
APP_NAME := $(IMAGE_NAME)
|
||||||
|
|
||||||
GOLANGCI_LINT_VERSION := v1.47.3
|
GOLANGCI_LINT_VERSION := v1.48.0
|
||||||
|
|
||||||
VERSION := $(shell git describe --exact-match HEAD 2>/dev/null || git describe --tags --always)
|
VERSION := $(shell git describe --exact-match HEAD 2>/dev/null || git describe --tags --always)
|
||||||
COMMON_BUILD_FLAGS := -trimpath -mod=readonly -ldflags="-extldflags '-static' -s -w -X 'main.version=$(VERSION)'"
|
COMMON_BUILD_FLAGS := -trimpath -mod=readonly -ldflags="-extldflags '-static' -s -w -X 'main.version=$(VERSION)'"
|
||||||
|
|||||||
+22
-30
@@ -21,31 +21,15 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func getVersion() string {
|
func getVersion() string {
|
||||||
goVersion, date, commit, modulesChecksum, dirty := getVersionData()
|
|
||||||
|
|
||||||
dirtySuffix := ""
|
|
||||||
if dirty {
|
|
||||||
dirtySuffix = " [dirty]"
|
|
||||||
}
|
|
||||||
|
|
||||||
return fmt.Sprintf("%s (%s: %s on %s%s, modules checksum %s)",
|
|
||||||
version,
|
|
||||||
goVersion,
|
|
||||||
date.Format(time.RFC3339),
|
|
||||||
commit,
|
|
||||||
dirtySuffix,
|
|
||||||
modulesChecksum)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getVersionData() (goVersion string, date time.Time, commit string, modulesChecksum string, dirty bool) {
|
|
||||||
date = time.Now()
|
|
||||||
|
|
||||||
buildInfo, ok := debug.ReadBuildInfo()
|
buildInfo, ok := debug.ReadBuildInfo()
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
goVersion = buildInfo.GoVersion
|
date := time.Now()
|
||||||
|
commit := ""
|
||||||
|
goVersion := buildInfo.GoVersion
|
||||||
|
dirtySuffix := ""
|
||||||
|
|
||||||
for _, setting := range buildInfo.Settings {
|
for _, setting := range buildInfo.Settings {
|
||||||
switch setting.Key {
|
switch setting.Key {
|
||||||
@@ -54,7 +38,9 @@ func getVersionData() (goVersion string, date time.Time, commit string, modulesC
|
|||||||
case "vcs.revision":
|
case "vcs.revision":
|
||||||
commit = setting.Value
|
commit = setting.Value
|
||||||
case "vcs.modified":
|
case "vcs.modified":
|
||||||
dirty, _ = strconv.ParseBool(setting.Value)
|
if dirty, _ := strconv.ParseBool(setting.Value); dirty {
|
||||||
|
dirtySuffix = " [dirty]"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,40 +48,46 @@ func getVersionData() (goVersion string, date time.Time, commit string, modulesC
|
|||||||
if _, err := io.WriteString(hasher, buildInfo.Path); err != nil {
|
if _, err := io.WriteString(hasher, buildInfo.Path); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
binary.Write(hasher, binary.LittleEndian, uint64(1+len(buildInfo.Deps)))
|
|
||||||
|
binary.Write(hasher, binary.LittleEndian, uint64(1+len(buildInfo.Deps))) //nolint: errcheck
|
||||||
|
|
||||||
sort.Slice(buildInfo.Deps, func(i, j int) bool {
|
sort.Slice(buildInfo.Deps, func(i, j int) bool {
|
||||||
return buildInfo.Deps[i].Path > buildInfo.Deps[j].Path
|
return buildInfo.Deps[i].Path > buildInfo.Deps[j].Path
|
||||||
})
|
})
|
||||||
|
|
||||||
buildInfoCheckSumModule(hasher, &buildInfo.Main)
|
buildInfoCheckSumModule(hasher, &buildInfo.Main)
|
||||||
|
|
||||||
for _, module := range buildInfo.Deps {
|
for _, module := range buildInfo.Deps {
|
||||||
buildInfoCheckSumModule(hasher, module)
|
buildInfoCheckSumModule(hasher, module)
|
||||||
}
|
}
|
||||||
|
|
||||||
modulesChecksum = base64.StdEncoding.EncodeToString(hasher.Sum(nil))
|
return fmt.Sprintf("%s (%s: %s on %s%s, modules checksum %s)",
|
||||||
|
version,
|
||||||
return
|
goVersion,
|
||||||
|
date.Format(time.RFC3339),
|
||||||
|
commit,
|
||||||
|
dirtySuffix,
|
||||||
|
base64.StdEncoding.EncodeToString(hasher.Sum(nil)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildInfoCheckSumModule(w io.Writer, module *debug.Module) {
|
func buildInfoCheckSumModule(w io.Writer, module *debug.Module) {
|
||||||
w.Write([]byte{buildInfoModuleStart})
|
w.Write([]byte{buildInfoModuleStart}) //nolint: errcheck
|
||||||
|
|
||||||
if _, err := io.WriteString(w, module.Path); err != nil {
|
if _, err := io.WriteString(w, module.Path); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write([]byte{buildInfoModuleDelimeter})
|
w.Write([]byte{buildInfoModuleDelimeter}) //nolint: errcheck
|
||||||
|
|
||||||
if _, err := io.WriteString(w, module.Version); err != nil {
|
if _, err := io.WriteString(w, module.Version); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write([]byte{buildInfoModuleDelimeter})
|
w.Write([]byte{buildInfoModuleDelimeter}) //nolint: errcheck
|
||||||
|
|
||||||
if _, err := io.WriteString(w, module.Sum); err != nil {
|
if _, err := io.WriteString(w, module.Sum); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write([]byte{buildInfoModuleFinish})
|
w.Write([]byte{buildInfoModuleFinish}) //nolint: errcheck
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -127,7 +127,12 @@ func makeIPAllowlist(conf config.ListConfig,
|
|||||||
logger mtglib.Logger,
|
logger mtglib.Logger,
|
||||||
ntw mtglib.Network,
|
ntw mtglib.Network,
|
||||||
updateCallback ipblocklist.FireholUpdateCallback,
|
updateCallback ipblocklist.FireholUpdateCallback,
|
||||||
) (allowlist mtglib.IPBlocklist, err error) {
|
) (mtglib.IPBlocklist, error) {
|
||||||
|
var (
|
||||||
|
allowlist mtglib.IPBlocklist
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
if !conf.Enabled.Get(false) {
|
if !conf.Enabled.Get(false) {
|
||||||
allowlist, err = ipblocklist.NewFireholFromFiles(
|
allowlist, err = ipblocklist.NewFireholFromFiles(
|
||||||
logger.Named("ipblocklist"),
|
logger.Named("ipblocklist"),
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// files defines a set of abstraction for 'files': an openable entities that
|
||||||
|
// could be read after.
|
||||||
|
//
|
||||||
|
// This is not a file on a filesystem of your local machine, it also can
|
||||||
|
// include "in memory" files or even remote ones, like HTTP endpoints. If you
|
||||||
|
// make a GET request to HTTP endpoint, then a body is readable and you can
|
||||||
|
// consider it as an openable file.
|
||||||
|
package files
|
||||||
@@ -24,7 +24,7 @@ func (suite *StreamContextTestSuite) SetupSuite() {
|
|||||||
|
|
||||||
func (suite *StreamContextTestSuite) SetupTest() {
|
func (suite *StreamContextTestSuite) SetupTest() {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
ctx = context.WithValue(ctx, "key", "value") // nolint: golint, revive, staticcheck
|
ctx = context.WithValue(ctx, "key", "value") //nolint: golint, staticcheck
|
||||||
|
|
||||||
suite.ctxCancel = cancel
|
suite.ctxCancel = cancel
|
||||||
suite.connMock = &testlib.EssentialsConnMock{}
|
suite.connMock = &testlib.EssentialsConnMock{}
|
||||||
|
|||||||
@@ -85,13 +85,13 @@ func (d *dnsResolver) LookupAAAA(hostname string) []string {
|
|||||||
return ips
|
return ips
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDNSResolver(hostname string, httpClient *http.Client) (ret *dnsResolver) {
|
func newDNSResolver(hostname string, httpClient *http.Client) *dnsResolver {
|
||||||
if net.ParseIP(hostname).To4() == nil {
|
if net.ParseIP(hostname).To4() == nil {
|
||||||
// the hostname is an IPv6 address
|
// the hostname is an IPv6 address
|
||||||
hostname = fmt.Sprintf("[%s]", hostname)
|
hostname = fmt.Sprintf("[%s]", hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = &dnsResolver{
|
return &dnsResolver{
|
||||||
resolver: doh.Resolver{
|
resolver: doh.Resolver{
|
||||||
Host: hostname,
|
Host: hostname,
|
||||||
Class: doh.IN,
|
Class: doh.IN,
|
||||||
@@ -99,6 +99,4 @@ func newDNSResolver(hostname string, httpClient *http.Client) (ret *dnsResolver)
|
|||||||
},
|
},
|
||||||
cache: map[string]dnsResolverCacheEntry{},
|
cache: map[string]dnsResolverCacheEntry{},
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,14 +14,14 @@ func setSocketReuseAddrPort(conn syscall.RawConn) error {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
conn.Control(func(fd uintptr) { //nolint: errcheck
|
conn.Control(func(fd uintptr) { //nolint: errcheck
|
||||||
err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1)
|
err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1) //nolint: nosnakecase
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("cannot set SO_REUSEADDR: %w", err)
|
err = fmt.Errorf("cannot set SO_REUSEADDR: %w", err)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1)
|
err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1) //nolint: nosnakecase
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("cannot set SO_REUSEPORT: %w", err)
|
err = fmt.Errorf("cannot set SO_REUSEPORT: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user