General

Code Style

  • Formatting: Use gofmt for standard Go formatting.
  • File naming: snake_case for files, test files end with _test.go.
    • Integration tests use _integration_test.go
  • Generated files: *.gen.go files are auto-generated - do not edit.
  • Error handling: Always check and handle errors appropriately.
  • Imports: Standard library, third-party, then internal imports.

Interfaces and Abstraction

  • Keep interfaces small and focused (single responsibility).
  • Prefer returning concrete types unless abstraction is required for testing or swapping implementations.
  • Document interface expectations explicitly (e.g. “implementations must be thread-safe”).

Defining Types

  • Keep structs small and cohesive; split if too many responsibilities.
  • Prefer to use the type keyword once for multiple type declarations.

Example

 1type (
 2	// Environment contains env-specific variable configurations.
 3	Environment struct {
 4		Dev        EnvVar `json:"dev,omitempty"`
 5		Staging    EnvVar `json:"staging,omitempty"`
 6		Production EnvVar `json:"production,omitempty"`
 7	}
 8	// EnvVar is a map of variable names to their configurations.
 9	EnvVar map[string]EnvValue
10	// EnvValue represents a single env variable configuration
11	EnvValue struct {
12		Source EnvSource `json:"source"`          // See below
13		Value  any       `json:"value,omitempty"` // Used for "value" and "resource" sources
14		Path   string    `json:"path,omitempty"`  // Used for "sops" source (format: "key")
15	}
16)

Naming Conventions

  • Integration tests: End with _integration_test.go.
  • Generated files: *.gen.go files are auto-generated - do not edit.
  • Interfaces: Often end in -er suffix (e.g., Reader, Writer, Store).
  • Package names: Short, lowercase, single-word names when possible.
Last modified: 27/10/2025 2022-2025 ©ainsley.dev, All rights reserved.