- Golang code standards are enforced specifically for user or agent-written code, not code that is automatically generated by tooling (example: unit test mocks)
- Receiver functions on structs should prefer
sas the variable name instead of the first letter of the struct type. - Named returns are not allowed; all return variables must be defined in the function.
- Group variable initializations in a
var ( ... )block and hoist them to the top of the function when possible. - Use
anyinstead ofinterface{}. - Prefer rich variables names, for example:
databaseInterfaceinstead ofdiordbi.
- Title format: : <Title>
- Always run
just prepare-for-codereviewbefore committing to perform tests and do code generation and license checks.
- If a test file is testing internal (non-exported) logic, the file may be included in the same package as the code being tested.
- If a test file is only testing the external (exported) pieces of code, the file should use the same package as the code being tested with
_testappended.- Example:
auth.gohaspackage api,auth_test.gois only testing exported logic inauth.goand should havepackage api_test
- Example:
- Integration tests should be separated from unit tests, such that if we have an
auth.gofile,auth_test.goshould have unit tests andauth_integration_test.goshould have integration tests. - Integration test files should have an
*integrationbuild tag at the top of the file, underneath the license header: example://go:build integrationor//go:build serial_integrationor//go:build slow_integration
- The user should have run
just prepare-for-codereviewbefore creating a PR. This command runs tests locally, does code generation, adds license headers, and generates OpenAPI docs. - There is no 100% positive way to identify that a user has run
just prepare-for-codereview, but there are some smells to look for which indicate that a user might not have run it:- Code files must have a license header at the top of the file using a code comment block. The file
LICENSE.headerfile has an up-to-date version of the header. - The file located at
cmd/api/src/database/db.gocontains a Database interface type. This interface must be implemented by theMockDatabasestruct incmd/api/src/database/mocks/db.goand is generated bygo.uber.org/mock/mockgen. - If the code adds a new API endpoint, or it changes something about an existing API endpoint (url, models that get marshaled to JSON, query params, etc), there should probably be changes to the OpenAPI yaml files.
- If OpenAPI yaml files have been changed,
openapi.jsonshould also have corresponding changes.
- Code files must have a license header at the top of the file using a code comment block. The file