Skip to content

Commit

Permalink
chore: refactor error handling and linter configurations
Browse files Browse the repository at this point in the history
- Add a new `.golangci.yml` file with linter configurations
- Remove `gin.SetMode(gin.TestMode)` from `zap_test.go` and move it to `zap.go`
- Modify error handling in `zap.go` to check for specific error messages

Signed-off-by: appleboy <appleboy.tw@gmail.com>
  • Loading branch information
appleboy committed Mar 2, 2024
1 parent 58dd173 commit 372417f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
39 changes: 39 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
linters:
enable-all: false
disable-all: true
fast: false
enable:
- bodyclose
- dogsled
- dupl
- errcheck
- exportloopref
- exhaustive
- gochecknoinits
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- noctx
- nolintlint
- rowserrcheck
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- whitespace
- gofumpt

run:
timeout: 3m
3 changes: 2 additions & 1 deletion zap.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ func CustomRecoveryWithZap(logger ZapLogger, stack bool, recovery gin.RecoveryFu
var brokenPipe bool
if ne, ok := err.(*net.OpError); ok {
if se, ok := ne.Err.(*os.SyscallError); ok {
if strings.Contains(strings.ToLower(se.Error()), "broken pipe") || strings.Contains(strings.ToLower(se.Error()), "connection reset by peer") {
if strings.Contains(strings.ToLower(se.Error()), "broken pipe") ||
strings.Contains(strings.ToLower(se.Error()), "connection reset by peer") {
brokenPipe = true
}
}
Expand Down
4 changes: 0 additions & 4 deletions zap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import (
"go.uber.org/zap/zaptest/observer"
)

func init() {
gin.SetMode(gin.TestMode)
}

func buildDummyLogger() (*zap.Logger, *observer.ObservedLogs) {
core, obs := observer.New(zap.InfoLevel)
logger := zap.New(core)
Expand Down

0 comments on commit 372417f

Please sign in to comment.