EF

Effective Go

Used in 23 go projects (avg ★4464)

Go
Style Guide
Default
Used by 23 projects

Details

Language / Topic
goGo
Category
Style Guide
Source
Go Team

Rules

balanced
- Run gofmt on every save and in CI — the Go community has no style debates; gofmt output is the canonical format.
- Use lowercase, single-word names for packages.
- Provide package documentation in doc.go and godoc comments for all public functions, types, variables, and fields.
- Handle errors explicitly by returning them and wrapping with fmt.Errorf("context: %w", err).
- Pass context.Context as the first parameter in functions that may block or be cancellable.
- Avoid global variables; manage state through function parameters and return values for better testability and clarity.
- Name interfaces using nouns or adjectives (e.g., Reader); use plain names for getters without "Get" prefix (e.g., Config()).
- Group related struct fields logically, such as dependencies followed by configuration.
- Use constructor functions like NewX to initialize structs and validate dependencies.
- Eliminate duplicate code to keep the codebase simple and maintainable.