Packages

Recommendations

Some rules to make go packages better:

  • Define domain-specific types, rather than relying on primitive ones, such as int or string, for improved readability and maintainability. For example, replacing int with a UserID type can make code clearer.
  • Use enumerations with iota when defining types with a small, finite set of possible values, such as states or modes. This approach ensures type safety and readability.

Rules

The following rules apply to Go packages:

  • A package is a collection of files located in the same folder that all share the same package name. Each Go file starts with the package declaration.
  • It’s customary to name the package after the name of the directory.
  • Avoid overly long names if possible; a lowercase single word is best. If you compress the word, avoid abbreviations that make the package name more ambiguous.
  • Any symbol (functions, types, variables, constants, etc.) starting with an uppercase letter will be exported outside the package and can be used by other packages, while those starting with a lowercase letter will not.