Skip to content

About

No description, website, or topics provided.

Resources

Stars

16 stars

Watchers

2 watching

Forks

Latest commit

 

History

24 Commits

Folders and files

Repository files navigation

Recovergoroutine

Summary

When operating a Go server, we typically use recover middleware. However, if using goroutines, a failure to handle a panic in a goroutine can result in server downtime. To address this, we can use recovergoroutine and check it through linting.

Supported Go Versions

0.2.0 and Below

  • Compatible with Go 1.19 and earlier versions.

0.3.0 and Above

  • Requires Go 1.20 and later versions.

Install

go install github.com/Buzzvil/recovergoroutine

Usage

recovergoroutine -recover="" ./...

# -recover string
#         Custom recovery method name. You can use this option
#         when you want to call a method defined in a struct or
#         use CustomRecover declared in an external package.

By default, the CLI checks the syntax of source and test files selected by Go's build rules. In v0.5.0, a package with only a type error caused the CLI to exit with code 1. The default command can now exit with code 0 for that package when it finds no goroutine violations. Run go test ./... in CI to catch type errors in both source and test files. go build ./... checks only non-test files.

Check out the test cases for validation examples.

# Output:
/Users/scott/Workspace/buzzvil/recovergoroutine/test/src/faildata/failcode.go:4:2: goroutine must have recover
/Users/scott/Workspace/buzzvil/recovergoroutine/test/src/faildata/failcode.go:10:2: goroutine must have recover
/Users/scott/Workspace/buzzvil/recovergoroutine/test/src/faildata/failcode.go:20:2: goroutine must have recover
/Users/scott/Workspace/buzzvil/recovergoroutine/test/src/faildata/failcode.go:25:2: goroutine must have recover
/Users/scott/Workspace/buzzvil/recovergoroutine/test/src/faildata/failcode.go:31:2: goroutine must have recover
/Users/scott/Workspace/buzzvil/recovergoroutine/test/src/faildata/failcode.go:32:2: goroutine must have recover

TODO

  • integrate with golangci-lint

About

No description, website, or topics provided.

Resources

Stars

16 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages