linters: # inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint disable-all: true enable: - deadcode - errcheck - gofmt - goimports - gosimple - govet - ineffassign - structcheck - typecheck - unused - varcheck run: tests: true
- Prefer to avoid Avoid logging directly at the site where an error is produced or returned. Instead , let the entry point to processing do the logging. If the returned error message is insufficient (often they are already sufficient) use
errors.Wrapto add context to the returned error and let the entry point to processing decide if and how these errors should be logged..
- Use the
github.com/pkg/errorspackage instead of
errors, and user
errors.WithStack(err)wherever an error is produced or returned from an external package.
WithStackproduces a stack trace pointing to the line of code which produced the error, which also prevents us from having to add our own custom error message so that we can correlate the error message to the line of code which produced it.This can also be done wherever there's an
In addition to the points raised above, we should endeavour to write idiomatic Go. Guidance for what these idioms are and how to follow them can be found in:
Commonly used libraries
- (Pending review and approval from others) Validator validates struct data to ensure input matches what's required. github.com/go-playground/validator