Compare commits
13 Commits
exegroup/v
...
log/v0.11.
| Author | SHA1 | Date | |
|---|---|---|---|
| d83a012967 | |||
| 850b678c13 | |||
| 66e4001f0e | |||
| b5095448fc | |||
| 13de8b9b6c | |||
| 046bd80bf9 | |||
| 0ad011081f | |||
| b483650651 | |||
| 1467db05fb | |||
| 6f50b2e715 | |||
| 6fd7badcb7 | |||
| 7c6fc1210c | |||
| d9e5a3371d |
138
cmd/http-reflect-server/.golangci.yaml
Normal file
138
cmd/http-reflect-server/.golangci.yaml
Normal file
@@ -0,0 +1,138 @@
|
||||
## 更新到 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
|
||||
- nosprintfhostport
|
||||
- prealloc
|
||||
- predeclared
|
||||
- promlinter
|
||||
- reassign
|
||||
- revive
|
||||
- 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:
|
||||
- ".*"
|
||||
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
|
||||
@@ -3,6 +3,6 @@ module git.blauwelle.com/go/crate/cmd/http-reflect-server
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
git.blauwelle.com/go/crate/exegroup v0.3.0
|
||||
git.blauwelle.com/go/crate/log v0.6.0
|
||||
git.blauwelle.com/go/crate/exegroup v0.4.0
|
||||
git.blauwelle.com/go/crate/log v0.9.0
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
git.blauwelle.com/go/crate/exegroup v0.3.0 h1:TBLygDztECKc67NeIIBsFDxlA4KcJpbOmafqqRuKRcM=
|
||||
git.blauwelle.com/go/crate/exegroup v0.3.0/go.mod h1:DJoID54YI5WFHGHoTCjBao8oS3HFRzwbWMZW6P57AIQ=
|
||||
git.blauwelle.com/go/crate/log v0.6.0 h1:s/TeJUaV/Y8hHaz/3FumdbwQWCbRMmOx8prrNmByJHs=
|
||||
git.blauwelle.com/go/crate/log v0.6.0/go.mod h1:jfVfpRODZTA70A8IkApVeGsS1zfLk1D77sLWZM/w+L0=
|
||||
git.blauwelle.com/go/crate/exegroup v0.4.0 h1:hr9vhYDL+LidvoEBCabdUZ22oekUq0s2NK69tklb42g=
|
||||
git.blauwelle.com/go/crate/exegroup v0.4.0/go.mod h1:DJoID54YI5WFHGHoTCjBao8oS3HFRzwbWMZW6P57AIQ=
|
||||
git.blauwelle.com/go/crate/log v0.9.0 h1:H01AQIKcYybeCZGdReBzMoWhkXPQJAoY1t+K0J1asEk=
|
||||
git.blauwelle.com/go/crate/log v0.9.0/go.mod h1:jfVfpRODZTA70A8IkApVeGsS1zfLk1D77sLWZM/w+L0=
|
||||
|
||||
@@ -12,6 +12,10 @@ import (
|
||||
"git.blauwelle.com/go/crate/log"
|
||||
)
|
||||
|
||||
const (
|
||||
maxParseMemory = 16 * 1024 * 1024
|
||||
)
|
||||
|
||||
func newHandler() http.HandlerFunc {
|
||||
return func(rw http.ResponseWriter, r *http.Request) {
|
||||
start := time.Now()
|
||||
@@ -59,7 +63,6 @@ func newHandler() http.HandlerFunc {
|
||||
log.Field("code", code),
|
||||
log.Field("duration", duration.String()),
|
||||
).Info(ctx, message)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,6 +96,7 @@ type ResponseRequest struct {
|
||||
ContentLength int64 `json:"contentLength"`
|
||||
}
|
||||
|
||||
//nolint:cyclop
|
||||
func readBody(ctx context.Context, r *http.Request) (any, error) {
|
||||
contentType := r.Header.Get("Content-Type")
|
||||
switch {
|
||||
@@ -122,7 +126,7 @@ func readBody(ctx context.Context, r *http.Request) (any, error) {
|
||||
return string(b), nil
|
||||
//case :
|
||||
case strings.HasPrefix(contentType, "multipart/form-data"):
|
||||
if err := r.ParseMultipartForm(16 * 1024 * 1024); err != nil {
|
||||
if err := r.ParseMultipartForm(maxParseMemory); err != nil {
|
||||
log.Error(ctx, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
@@ -148,8 +152,9 @@ func readBody(ctx context.Context, r *http.Request) (any, error) {
|
||||
log.Error(ctx, err.Error())
|
||||
return nil, err
|
||||
}
|
||||
if len(b) > 96 {
|
||||
b = b[:96]
|
||||
const maxBodyByteSizeToReturn = 96
|
||||
if len(b) > maxBodyByteSizeToReturn {
|
||||
b = b[:maxBodyByteSizeToReturn]
|
||||
}
|
||||
return b, nil
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"git.blauwelle.com/go/crate/log/logsdk/logjson"
|
||||
)
|
||||
|
||||
var port = flag.Int("port", 8080, "HTTP Port")
|
||||
var port = flag.Int("port", 8080, "HTTP Port") //nolint:gomnd
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
@@ -20,7 +20,7 @@ func main() {
|
||||
mux := http.NewServeMux()
|
||||
var handler http.Handler = mux
|
||||
mux.HandleFunc("/", newHandler())
|
||||
g.New().WithGoStop(exegroup.HttpListenAndServe(*port, handler))
|
||||
g.New().WithGoStop(exegroup.HTTPListenAndServe(*port, handler))
|
||||
log.Infof(context.Background(), "listening %d", *port)
|
||||
log.Error(context.Background(), "exit: ", g.Run(context.Background()))
|
||||
}
|
||||
|
||||
138
cmd/retry/.golangci.yaml
Normal file
138
cmd/retry/.golangci.yaml
Normal file
@@ -0,0 +1,138 @@
|
||||
## 更新到 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
|
||||
- nosprintfhostport
|
||||
- prealloc
|
||||
- predeclared
|
||||
- promlinter
|
||||
- reassign
|
||||
- revive
|
||||
- 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:
|
||||
- ".*"
|
||||
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
|
||||
@@ -14,7 +14,7 @@ var (
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.IntVar(&count, "c", 5, "maximum execution times")
|
||||
flag.IntVar(&count, "c", 5, "maximum execution times") //nolint:gomnd
|
||||
flag.DurationVar(&interval, "i", time.Second, "retry interval")
|
||||
flag.Parse()
|
||||
if count < 1 {
|
||||
@@ -34,7 +34,7 @@ func main() {
|
||||
fmt.Printf("retry %d after %s...\n", i, interval)
|
||||
time.Sleep(interval)
|
||||
}
|
||||
cmd := exec.Command(args[0], args[1:]...)
|
||||
cmd := exec.Command(args[0], args[1:]...) // #nosec G204
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err = cmd.Run()
|
||||
|
||||
138
concurrentsafemapset/.golangci.yaml
Normal file
138
concurrentsafemapset/.golangci.yaml
Normal file
@@ -0,0 +1,138 @@
|
||||
## 更新到 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
|
||||
- nosprintfhostport
|
||||
- prealloc
|
||||
- predeclared
|
||||
- promlinter
|
||||
- reassign
|
||||
- revive
|
||||
- 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:
|
||||
- ".*"
|
||||
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
|
||||
138
contexthelper/.golangci.yaml
Normal file
138
contexthelper/.golangci.yaml
Normal file
@@ -0,0 +1,138 @@
|
||||
## 更新到 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
|
||||
- nosprintfhostport
|
||||
- prealloc
|
||||
- predeclared
|
||||
- promlinter
|
||||
- reassign
|
||||
- revive
|
||||
- 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:
|
||||
- ".*"
|
||||
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
|
||||
@@ -8,6 +8,7 @@ func WithNoCancel(ctx context.Context) context.Context {
|
||||
return &noCancelCtx{Context: ctx}
|
||||
}
|
||||
|
||||
//nolint:containedctx
|
||||
type noCancelCtx struct {
|
||||
context.Context
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ log.Logger()
|
||||
- `SetReportStack` 设置生成调用栈;
|
||||
- `SetReportStackLevel` 当日志等级小于设定值时强制生成调用栈;
|
||||
- `Reset` 把 Logger 恢复到初始状态;
|
||||
- `AddBeforeExit` 新增调用 `Logger.Exit` 时优先执行的函数, 先增加的后执行;
|
||||
- `SetExit` 设置 `Logger` 的退出函数(`Logger.Exit`), 当日志等级为 `LevelFatal` 时调用这个函数;
|
||||
|
||||
### 日志生成
|
||||
|
||||
@@ -150,6 +150,11 @@ func Panicf(ctx context.Context, format string, args ...any) {
|
||||
globalLogger.AddCallerSkip(1).Panicf(ctx, format, args...)
|
||||
}
|
||||
|
||||
// Exit 调用全局 logger 的 Exit
|
||||
func Exit(code int) {
|
||||
globalLogger.Exit(code)
|
||||
}
|
||||
|
||||
// Logger 返回全局 logger, 通常用来在程序启动时对全局 logger 进行配置,
|
||||
// 业务代码处理日志时直接使用这个包里定义的日志函数.
|
||||
func Logger() *logsdk.Logger {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package logsdk
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Level 日志等级
|
||||
type Level int
|
||||
@@ -12,6 +14,30 @@ func (level Level) String() string {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
// ParseLevel 把 level 字符串解析成 Level,
|
||||
// 支持的字符串: panic, fatal, error, warn, info, debug, trace,
|
||||
// 传入不支持的字符串返回 LevelInfo.
|
||||
func ParseLevel(s string) Level {
|
||||
switch s {
|
||||
case LevelPanicValue:
|
||||
return LevelPanic
|
||||
case LevelFatalValue:
|
||||
return LevelFatal
|
||||
case LevelErrorValue:
|
||||
return LevelError
|
||||
case LevelWarnValue:
|
||||
return LevelWarn
|
||||
case LevelInfoValue:
|
||||
return LevelInfo
|
||||
case LevelDebugValue:
|
||||
return LevelDebug
|
||||
case LevelTraceValue:
|
||||
return LevelTrace
|
||||
default:
|
||||
return LevelInfo
|
||||
}
|
||||
}
|
||||
|
||||
func (level Level) MarshalText() ([]byte, error) {
|
||||
switch level {
|
||||
case LevelPanic:
|
||||
|
||||
@@ -20,8 +20,9 @@ type entry = Entry
|
||||
// Logger 中保存了日志所需的全局配置,
|
||||
// 使用 Logger 处理日志.
|
||||
type Logger struct {
|
||||
exit func(code int) // protected by lock
|
||||
levelProcessors levelProcessors // protected by lock
|
||||
exit func(code int) // protected by lock
|
||||
beforeExit []func(code int) // protected by lock
|
||||
levelProcessors levelProcessors // protected by lock
|
||||
entry
|
||||
lock sync.RWMutex
|
||||
level atomic.Int32
|
||||
@@ -98,6 +99,7 @@ func (logger *Logger) SetReportStackLevel(level Level) {
|
||||
func (logger *Logger) Reset() {
|
||||
logger.lock.Lock()
|
||||
logger.exit = nil
|
||||
logger.beforeExit = nil
|
||||
logger.levelProcessors = levelProcessors{}
|
||||
logger.lock.Unlock()
|
||||
|
||||
@@ -112,9 +114,14 @@ func (logger *Logger) Reset() {
|
||||
func (logger *Logger) Exit(code int) {
|
||||
logger.lock.RLock()
|
||||
exit := logger.exit
|
||||
beforeExit := make([]func(int), len(logger.beforeExit))
|
||||
copy(beforeExit, logger.beforeExit)
|
||||
logger.lock.RUnlock()
|
||||
for i := len(beforeExit) - 1; i >= 0; i-- {
|
||||
beforeExit[i](code)
|
||||
}
|
||||
if exit == nil {
|
||||
os.Exit(code)
|
||||
exit = os.Exit
|
||||
}
|
||||
exit(code)
|
||||
}
|
||||
@@ -126,6 +133,14 @@ func (logger *Logger) SetExit(fn func(code int)) {
|
||||
logger.lock.Unlock()
|
||||
}
|
||||
|
||||
// AddBeforeExit 增加 Exit 在调用 SetExit 指定的函数前执行的函数,
|
||||
// 先增加的后执行.
|
||||
func (logger *Logger) AddBeforeExit(fn ...func(code int)) {
|
||||
logger.lock.Lock()
|
||||
logger.beforeExit = append(logger.beforeExit, fn...)
|
||||
logger.lock.Unlock()
|
||||
}
|
||||
|
||||
func (logger *Logger) getLevelProcessors(level Level) []EntryProcessor {
|
||||
logger.lock.RLock()
|
||||
defer logger.lock.RUnlock()
|
||||
|
||||
141
logotel/.golangci.yaml
Normal file
141
logotel/.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
|
||||
@@ -3,7 +3,7 @@ module git.blauwelle.com/go/crate/logotel
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
git.blauwelle.com/go/crate/log v0.8.0
|
||||
git.blauwelle.com/go/crate/log v0.9.0
|
||||
go.opentelemetry.io/otel v1.13.0
|
||||
go.opentelemetry.io/otel/trace v1.13.0
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
git.blauwelle.com/go/crate/log v0.8.0 h1:TINzuFo330MZIagzdULouwBoLCcLIB4yjI/G1IH0I+0=
|
||||
git.blauwelle.com/go/crate/log v0.8.0/go.mod h1:jfVfpRODZTA70A8IkApVeGsS1zfLk1D77sLWZM/w+L0=
|
||||
git.blauwelle.com/go/crate/log v0.9.0 h1:H01AQIKcYybeCZGdReBzMoWhkXPQJAoY1t+K0J1asEk=
|
||||
git.blauwelle.com/go/crate/log v0.9.0/go.mod h1:jfVfpRODZTA70A8IkApVeGsS1zfLk1D77sLWZM/w+L0=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
|
||||
@@ -4,13 +4,18 @@ import (
|
||||
"git.blauwelle.com/go/crate/log/logsdk/logjson"
|
||||
)
|
||||
|
||||
const (
|
||||
bytesBufferInitialSize = 512
|
||||
bytesBufferMaximumSize = 4096
|
||||
)
|
||||
|
||||
func newConfig(opts ...Option) *config {
|
||||
cfg := defaultConfig()
|
||||
for _, opt := range opts {
|
||||
opt.apply(cfg)
|
||||
}
|
||||
if !cfg.hasPool {
|
||||
cfg.bytesBufferPool = logjson.NewBytesBufferPool(512, 4096)
|
||||
cfg.bytesBufferPool = logjson.NewBytesBufferPool(bytesBufferInitialSize, bytesBufferMaximumSize)
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
@@ -36,7 +36,8 @@ func (processor *Processor) Process(ctx context.Context, entry logsdk.ReadonlyEn
|
||||
return
|
||||
}
|
||||
|
||||
attrs := make([]attribute.KeyValue, 0, len(entry.Fields)+6)
|
||||
const entryInitSize = 6
|
||||
attrs := make([]attribute.KeyValue, 0, len(entry.Fields)+entryInitSize)
|
||||
attrs = append(attrs, attribute.String("log.severity", entry.Level.String()))
|
||||
attrs = append(attrs, attribute.String("log.message", entry.Message))
|
||||
if entry.Caller.IsValid() {
|
||||
|
||||
138
mapset/.golangci.yaml
Normal file
138
mapset/.golangci.yaml
Normal file
@@ -0,0 +1,138 @@
|
||||
## 更新到 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
|
||||
- nosprintfhostport
|
||||
- prealloc
|
||||
- predeclared
|
||||
- promlinter
|
||||
- reassign
|
||||
- revive
|
||||
- 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:
|
||||
- ".*"
|
||||
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
|
||||
@@ -7,6 +7,10 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
maximumItemToPrint = 64
|
||||
)
|
||||
|
||||
// New 返回 [MapSet]
|
||||
func New[T comparable](keys ...T) MapSet[T] {
|
||||
s := make(MapSet[T], len(keys))
|
||||
@@ -267,8 +271,8 @@ func (s *MapSet[T]) UnmarshalJSON(b []byte) error {
|
||||
|
||||
func (s MapSet[T]) String() string {
|
||||
size := s.Cardinality()
|
||||
if size > 64 {
|
||||
size = 64
|
||||
if size > maximumItemToPrint {
|
||||
size = maximumItemToPrint
|
||||
}
|
||||
keys := make([]string, 0, size)
|
||||
for key := range s {
|
||||
|
||||
138
runtimehelper/.golangci.yaml
Normal file
138
runtimehelper/.golangci.yaml
Normal file
@@ -0,0 +1,138 @@
|
||||
## 更新到 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
|
||||
- nosprintfhostport
|
||||
- prealloc
|
||||
- predeclared
|
||||
- promlinter
|
||||
- reassign
|
||||
- revive
|
||||
- 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:
|
||||
- ".*"
|
||||
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
|
||||
@@ -6,6 +6,11 @@ import (
|
||||
"runtime"
|
||||
)
|
||||
|
||||
const (
|
||||
callerSkipOffset = 2
|
||||
maximumFrames = 32
|
||||
)
|
||||
|
||||
// Frame 调用相关信息
|
||||
type Frame struct {
|
||||
Function string `json:"func"`
|
||||
@@ -38,7 +43,7 @@ func (frame Frame) SplitFunction() (string, string) {
|
||||
// skip=0 表示调用 Caller 处.
|
||||
func Caller(skip int) Frame {
|
||||
pc := make([]uintptr, 1)
|
||||
n := runtime.Callers(skip+2, pc)
|
||||
n := runtime.Callers(skip+callerSkipOffset, pc)
|
||||
frame, _ := runtime.CallersFrames(pc[:n]).Next()
|
||||
if frame.PC == 0 {
|
||||
return Frame{}
|
||||
@@ -54,7 +59,7 @@ func Caller(skip int) Frame {
|
||||
// skip=0 表示调用 Stack 处.
|
||||
func Stack(skip, maximumFrames int) []Frame {
|
||||
pc := make([]uintptr, maximumFrames)
|
||||
n := runtime.Callers(skip+2, pc)
|
||||
n := runtime.Callers(skip+callerSkipOffset, pc)
|
||||
stack := make([]Frame, 0, n)
|
||||
frames := runtime.CallersFrames(pc[:n])
|
||||
for {
|
||||
@@ -82,7 +87,7 @@ func Stack(skip, maximumFrames int) []Frame {
|
||||
// 可以使用 [runtime.Frame.PC] != 0 判断 runtime.Frame 有效
|
||||
func CallerFrame(skip int) runtime.Frame {
|
||||
pc := make([]uintptr, 1)
|
||||
n := runtime.Callers(skip+2, pc)
|
||||
n := runtime.Callers(skip+callerSkipOffset, pc)
|
||||
frame, _ := runtime.CallersFrames(pc[:n]).Next()
|
||||
return frame
|
||||
}
|
||||
@@ -95,14 +100,14 @@ func CallerFrame(skip int) runtime.Frame {
|
||||
// - 0: 调用 CallersFrames 处
|
||||
func CallersFrames(skip, maximumFrames int) *runtime.Frames {
|
||||
pc := make([]uintptr, maximumFrames)
|
||||
n := runtime.Callers(skip+2, pc)
|
||||
n := runtime.Callers(skip+callerSkipOffset, pc)
|
||||
return runtime.CallersFrames(pc[:n])
|
||||
}
|
||||
|
||||
// PrintCallersFrames 打印函数调用栈,
|
||||
// 从调用 PrintCallersFrames 的地方开始打印
|
||||
func PrintCallersFrames() {
|
||||
frames := CallersFrames(3, 32)
|
||||
frames := CallersFrames(callerSkipOffset+1, maximumFrames)
|
||||
for {
|
||||
frame, more := frames.Next()
|
||||
if frame.PC != 0 {
|
||||
|
||||
138
synchelper/.golangci.yaml
Normal file
138
synchelper/.golangci.yaml
Normal file
@@ -0,0 +1,138 @@
|
||||
## 更新到 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
|
||||
- nosprintfhostport
|
||||
- prealloc
|
||||
- predeclared
|
||||
- promlinter
|
||||
- reassign
|
||||
- revive
|
||||
- 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:
|
||||
- ".*"
|
||||
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
|
||||
@@ -18,7 +18,7 @@ type syncWriter struct {
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
func (w *syncWriter) Write(p []byte) (n int, err error) {
|
||||
func (w *syncWriter) Write(p []byte) (int, error) {
|
||||
w.lock.Lock()
|
||||
defer w.lock.Unlock()
|
||||
return w.writer.Write(p)
|
||||
|
||||
138
timehelper/.golangci.yaml
Normal file
138
timehelper/.golangci.yaml
Normal file
@@ -0,0 +1,138 @@
|
||||
## 更新到 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
|
||||
- nosprintfhostport
|
||||
- prealloc
|
||||
- predeclared
|
||||
- promlinter
|
||||
- reassign
|
||||
- revive
|
||||
- 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:
|
||||
- ".*"
|
||||
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
|
||||
@@ -4,5 +4,5 @@ import "time"
|
||||
|
||||
// SetupCST 把本地时区固定到CST
|
||||
func SetupCST() {
|
||||
time.Local = time.FixedZone("CST", 8*3600)
|
||||
time.Local = time.FixedZone("CST", 8*3600) //nolint:gomnd,reassign
|
||||
}
|
||||
|
||||
@@ -14,20 +14,20 @@ func ExampleRFC3339Nano() {
|
||||
// Output: 2023-01-15T15:16:17.123456789+08:00
|
||||
}
|
||||
|
||||
func ExampleRFC3339Nano2Sec() {
|
||||
func ExampleRFC3339_nano2Sec() {
|
||||
t, _ := time.Parse(time.RFC3339Nano, "2023-01-15T15:16:17.123456789+08:00")
|
||||
fmt.Println(t.Format(time.RFC3339))
|
||||
// Output: 2023-01-15T15:16:17+08:00
|
||||
}
|
||||
|
||||
// 使用 RFC3339 没有丢失纳秒精度
|
||||
func ExampleRFC3339Sec2Nano() {
|
||||
func ExampleRFC3339_sec2Nano() {
|
||||
t, _ := time.Parse(time.RFC3339, "2023-01-15T15:16:17.123456789+08:00")
|
||||
fmt.Println(t.Format(time.RFC3339Nano))
|
||||
// Output: 2023-01-15T15:16:17.123456789+08:00
|
||||
}
|
||||
|
||||
func ExampleRFC3339NanoOtherZone() {
|
||||
func ExampleRFC3339_nanoOtherZone() {
|
||||
t, _ := time.Parse(time.RFC3339Nano, "2023-01-15T15:16:17.123456789+09:00")
|
||||
fmt.Println(t.Format(time.RFC3339Nano))
|
||||
// Output: 2023-01-15T15:16:17.123456789+09:00
|
||||
|
||||
138
uptracehelper/.golangci.yaml
Normal file
138
uptracehelper/.golangci.yaml
Normal file
@@ -0,0 +1,138 @@
|
||||
## 更新到 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
|
||||
- nosprintfhostport
|
||||
- prealloc
|
||||
- predeclared
|
||||
- promlinter
|
||||
- reassign
|
||||
- revive
|
||||
- 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:
|
||||
- ".*"
|
||||
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
|
||||
@@ -23,7 +23,7 @@ require (
|
||||
go.opentelemetry.io/otel/sdk/metric v0.36.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.13.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
|
||||
golang.org/x/net v0.6.0 // indirect
|
||||
golang.org/x/net v0.7.0 // indirect
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
golang.org/x/text v0.7.0 // indirect
|
||||
google.golang.org/genproto v0.0.0-20230202175211-008b39050e57 // indirect
|
||||
|
||||
@@ -250,6 +250,8 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81R
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.6.0 h1:L4ZwwTvKW9gr0ZMS1yrHD9GZhIuVjOBBnaKH+SPQK0Q=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g=
|
||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
|
||||
138
wireexample/.golangci.yaml
Normal file
138
wireexample/.golangci.yaml
Normal file
@@ -0,0 +1,138 @@
|
||||
## 更新到 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
|
||||
- nosprintfhostport
|
||||
- prealloc
|
||||
- predeclared
|
||||
- promlinter
|
||||
- reassign
|
||||
- revive
|
||||
- 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:
|
||||
- ".*"
|
||||
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
|
||||
@@ -16,7 +16,7 @@ func approachA() {
|
||||
rander := &MockRander{}
|
||||
guess := InjectGuessWithoutMock(rander)
|
||||
rander.Value = 1
|
||||
fmt.Println("approachA:", guess.Guess(10))
|
||||
fmt.Println("approachA:", guess.Guess(10)) //nolint:gomnd
|
||||
}
|
||||
|
||||
// approach B:
|
||||
@@ -25,5 +25,5 @@ func approachA() {
|
||||
func approachB() {
|
||||
guessWithMock := InjectMockGuess()
|
||||
guessWithMock.Mock.Value = 1
|
||||
fmt.Println("approachB:", guessWithMock.Guess.Guess(10))
|
||||
fmt.Println("approachB:", guessWithMock.Guess.Guess(10)) //nolint:gomnd
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ type Rander interface {
|
||||
type DefaultRander struct{}
|
||||
|
||||
func (r *DefaultRander) Rand() int {
|
||||
return rand.Int()
|
||||
return rand.Int() //nolint:gosec
|
||||
}
|
||||
|
||||
func NewRander() *DefaultRander {
|
||||
|
||||
Reference in New Issue
Block a user