exegroup/基于golangci-lint修改代码;
This commit is contained in:
141
exegroup/.golangci.yaml
Normal file
141
exegroup/.golangci.yaml
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
## 基于 golangci-lint@v1.52.2
|
||||||
|
run:
|
||||||
|
timeout: 1m
|
||||||
|
build-tags: [ ]
|
||||||
|
skip-dirs: [ ]
|
||||||
|
skip-files: [ ]
|
||||||
|
linters:
|
||||||
|
disable-all: true
|
||||||
|
enable:
|
||||||
|
- errcheck
|
||||||
|
- gosimple
|
||||||
|
- govet
|
||||||
|
- ineffassign
|
||||||
|
- staticcheck
|
||||||
|
- typecheck
|
||||||
|
- unused
|
||||||
|
- asasalint
|
||||||
|
- asciicheck
|
||||||
|
- bidichk
|
||||||
|
- bodyclose
|
||||||
|
- containedctx
|
||||||
|
- cyclop
|
||||||
|
- dupl
|
||||||
|
- durationcheck
|
||||||
|
- errname
|
||||||
|
- errorlint
|
||||||
|
- exhaustive
|
||||||
|
- exportloopref
|
||||||
|
- funlen
|
||||||
|
- gocheckcompilerdirectives
|
||||||
|
- gochecknoinits
|
||||||
|
- goconst
|
||||||
|
- gocritic
|
||||||
|
- gocyclo
|
||||||
|
- goimports
|
||||||
|
- gomnd
|
||||||
|
- goprintffuncname
|
||||||
|
- gosec
|
||||||
|
- lll
|
||||||
|
- loggercheck
|
||||||
|
- makezero
|
||||||
|
- nakedret
|
||||||
|
- nestif
|
||||||
|
- nilnil
|
||||||
|
- noctx
|
||||||
|
- nolintlint
|
||||||
|
- prealloc
|
||||||
|
- predeclared
|
||||||
|
- promlinter
|
||||||
|
- reassign
|
||||||
|
- revive
|
||||||
|
- rowserrcheck
|
||||||
|
- stylecheck
|
||||||
|
- tenv
|
||||||
|
- testableexamples
|
||||||
|
- testpackage
|
||||||
|
- tparallel
|
||||||
|
- unconvert
|
||||||
|
- unparam
|
||||||
|
- usestdlibvars
|
||||||
|
- wastedassign
|
||||||
|
- whitespace
|
||||||
|
linters-settings:
|
||||||
|
errcheck:
|
||||||
|
check-type-assertions: true
|
||||||
|
exclude-functions: [ ]
|
||||||
|
govet:
|
||||||
|
enable-all: true
|
||||||
|
disable: [ ]
|
||||||
|
cyclop:
|
||||||
|
max-complexity: 10
|
||||||
|
package-average: 0.0
|
||||||
|
dupl:
|
||||||
|
threshold: 150
|
||||||
|
exhaustive:
|
||||||
|
check:
|
||||||
|
- switch
|
||||||
|
- map
|
||||||
|
funlen:
|
||||||
|
lines: 100
|
||||||
|
statements: 60
|
||||||
|
gocritic:
|
||||||
|
disabled-checks:
|
||||||
|
- commentFormatting
|
||||||
|
settings:
|
||||||
|
captLocal:
|
||||||
|
paramsOnly: false
|
||||||
|
underef:
|
||||||
|
skipRecvDeref: false
|
||||||
|
gocyclo:
|
||||||
|
min-complexity: 20
|
||||||
|
gomnd:
|
||||||
|
ignored-functions:
|
||||||
|
- os.Chmod
|
||||||
|
- os.Mkdir
|
||||||
|
- os.MkdirAll
|
||||||
|
- os.OpenFile
|
||||||
|
- os.WriteFile
|
||||||
|
- prometheus.ExponentialBuckets
|
||||||
|
- prometheus.ExponentialBucketsRange
|
||||||
|
- prometheus.LinearBuckets
|
||||||
|
lll:
|
||||||
|
line-length: 240
|
||||||
|
nakedret:
|
||||||
|
max-func-lines: 10
|
||||||
|
nestif:
|
||||||
|
min-complexity: 5
|
||||||
|
predeclared:
|
||||||
|
ignore: ""
|
||||||
|
q: false
|
||||||
|
reassign:
|
||||||
|
patterns:
|
||||||
|
- ".*"
|
||||||
|
rowserrcheck:
|
||||||
|
packages:
|
||||||
|
- github.com/jmoiron/sqlx
|
||||||
|
tenv:
|
||||||
|
all: true
|
||||||
|
usestdlibvars:
|
||||||
|
time-month: true
|
||||||
|
time-layout: true
|
||||||
|
crypto-hash: true
|
||||||
|
default-rpc-path: true
|
||||||
|
os-dev-null: true
|
||||||
|
sql-isolation-level: true
|
||||||
|
tls-signature-scheme: true
|
||||||
|
constant-kind: true
|
||||||
|
syslog-priority: true
|
||||||
|
issues:
|
||||||
|
max-same-issues: 10
|
||||||
|
exclude-rules:
|
||||||
|
- source: "//noinspection"
|
||||||
|
linters: [ gocritic ]
|
||||||
|
- path: "_test\\.go"
|
||||||
|
linters:
|
||||||
|
- bodyclose
|
||||||
|
- dupl
|
||||||
|
- funlen
|
||||||
|
- goconst
|
||||||
|
- gosec
|
||||||
|
- noctx
|
||||||
@@ -123,8 +123,8 @@ func (g *Group) start(ctx context.Context, c chan error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *Group) wait(c chan error, cancel context.CancelFunc) (err error) {
|
func (g *Group) wait(c chan error, cancel context.CancelFunc) error {
|
||||||
err = <-c
|
err := <-c
|
||||||
cancel()
|
cancel()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
if g.cfg.stopTimeout > 0 {
|
if g.cfg.stopTimeout > 0 {
|
||||||
@@ -144,10 +144,10 @@ func (g *Group) wait(c chan error, cancel context.CancelFunc) (err error) {
|
|||||||
select {
|
select {
|
||||||
case <-c:
|
case <-c:
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
|
|||||||
@@ -14,4 +14,5 @@ func Example_defaultGroup() {
|
|||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
})
|
})
|
||||||
log.Println("exit:", g.Run(context.Background()))
|
log.Println("exit:", g.Run(context.Background()))
|
||||||
|
// Output:
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,14 +2,20 @@ package exegroup
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HttpListenAndServe 提供 [http.Server] 的启动和停止函数;
|
// HTTPListenAndServe 提供 [http.Server] 的启动和停止函数;
|
||||||
func HttpListenAndServe(port int, handler http.Handler) (func(ctx context.Context) error, func(ctx context.Context)) {
|
func HTTPListenAndServe(port int, handler http.Handler) (func(ctx context.Context) error, func(ctx context.Context)) {
|
||||||
server := &http.Server{Addr: fmt.Sprintf(":%d", port), Handler: handler}
|
server := &http.Server{
|
||||||
|
Addr: net.JoinHostPort("", strconv.Itoa(port)),
|
||||||
|
Handler: handler,
|
||||||
|
ReadHeaderTimeout: time.Second,
|
||||||
|
}
|
||||||
inShutdown := &atomic.Bool{}
|
inShutdown := &atomic.Bool{}
|
||||||
c := make(chan error, 1)
|
c := make(chan error, 1)
|
||||||
goFunc := func(_ context.Context) error {
|
goFunc := func(_ context.Context) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user