Naming Conventions
Package Names
- Use lowercase: All package names should be lowercase, single words
- No underscores and no camelCase:
s3serviceorstorage, nots3_serviceors3Service. An underscore in a package name is rejected byrevive'spackage-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
modelnotmodels,endpointnotendpoints - Reflect functionality: Package name should reflect its purpose
go
// Good
package user
package database
package config
// Bad
package userStuff
package CommonVariable Names
Use camelCase for unexported (private) variables:
govar connectionString string var maxRetries intUse PascalCase for exported (public) variables:
govar MaxConnections int var DefaultTimeout time.DurationUse short names for limited scope:
gofor i := 0; i < len(items); i++ { /* ... */ }Descriptive names for broader scope:
govar 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.SecondUse ALL_CAPS with underscores only for special "enumeration" constants:
goconst ( USER_ROLE_ADMIN = iota USER_ROLE_MANAGER USER_ROLE_GUEST )
File Names
Use snake_case for file names:
user_service.go database_connection.goTest files should end with "_test.go":
user_service_test.goFiles that are meant to be compiled as executables should be named "main.go"