Skip to content

Latest commit

 

History

History
27 lines (25 loc) · 1.57 KB

code-conventions.md

File metadata and controls

27 lines (25 loc) · 1.57 KB

Code conventions

This document outlines key code conventions followed in this project.

Go

  1. Avoid utility packages
    Do not use generic utility package names like base, util, or common. For more context, see Dave Cheney's post explaining why.
  2. Error wrapping
    Errors should always be wrapped with fmt.Errorf with the %w directive. The wrapped message must provide enough context to help identify the error’s source at a glance. Avoid prefixes like "failed to" or "error" in messages, as they add no meaningful context.
    • Bad Example
      A generic message that doesn’t provide specific context:
      if _, err := os.Create(configFileName); err != nil {
        return fmt.Errorf("failed to create file: %v", err)
      }
    • Good Example
      A more specific message that clarifies the error’s context:
      if _, err := os.Create(configFileName); err != nil {
        return fmt.Errorf("create config file: %w", err)
      }
  3. Struct constructors
    Struct constructors are specifically created for use within app.go and main.go. They may initialize dependency fields with meaningful defaults and use static variables from other packages. An implication of this is that public tests should use constructors to initialize structs, and private tests may create a struct manually.

See also