Skip to content

Naming Conventions ​

Package Names ​

  • Use lowercase: All package names should be lowercase, single words
  • No underscores and no camelCase: s3service or storage, not s3_service or s3Service. An underscore in a package name is rejected by revive's package-naming, which this playbook requires, so it cannot satisfy the Definition of Done.
  • Short and concise: Package names should be short but descriptive
  • Not plural: Use model not models, endpoint not endpoints
  • Reflect functionality: Package name should reflect its purpose
go
// Good
package user
package database
package config

// Bad
package userStuff
package Common

Variable Names ​

  • Use camelCase for unexported (private) variables:

    go
    var connectionString string
    var maxRetries int
  • Use PascalCase for exported (public) variables:

    go
    var MaxConnections int
    var DefaultTimeout time.Duration
  • Use short names for limited scope:

    go
    for i := 0; i < len(items); i++ { /* ... */ }
  • Descriptive names for broader scope:

    go
    var currentUserCount int // Better than just 'count'

Constant Names ​

  • Follow the same case convention as variables:

    go
    // Unexported (private) constants
    const maxRetryCount = 5
    const defaultTimeout = 30 * time.Second
    
    // Exported (public) constants
    const MaxRetryCount = 5
    const DefaultTimeout = 30 * time.Second
  • Use ALL_CAPS with underscores only for special "enumeration" constants:

    go
    const (
        USER_ROLE_ADMIN = iota
        USER_ROLE_MANAGER
        USER_ROLE_GUEST
    )

File Names ​

  • Use snake_case for file names:

    user_service.go
    database_connection.go
  • Test files should end with "_test.go":

    user_service_test.go
  • Files that are meant to be compiled as executables should be named "main.go"