# Golang
- Use layers, not groups (opens new window).
- Follow standart go project layout (opens new window)
- Use Go Modules.
- Apply vendoring
go mod vendor
. - Enable Snyk scanner (opens new window) for your IDE.
- Upgrade (opens new window) dependencies.
- Enable Golang Linter (opens new window) for your IDE.
- Store the tests in the same directories as the code.
- Avoid global variables.
# Preferred packages
- Routing https://github.com/gorilla/mux.
- Working with dotenv files https://github.com/caarlos0/env and https://github.com/joho/godotenv.
- Asserts lib https://godoc.org/github.com/stretchr/testify/assert.
- Mocks https://godoc.org/github.com/stretchr/testify/mock.
# Test naming convention
The test function name follows the format of Test + the name of the package where the function is placed, with the function name appended after an underscore (_). For example, the Server.Debug.Enable()
function is tested in the TestServer_DebugEnable
test function. Similarly, the Server.SetupConfig
is tested in TestServer_SetupConfig
test function.
There are functions like Server.Config()
that require more specific tests. That’s why, for example there are TestServer_Config
and TestServer_ConfigWithSpecialContext
, where in the latter there is more specific functionality being tested.
func TestServer_Config(t *testing.T) {
...
}
func TestServer_ConfigWithSpecialContext(t *testing.T) {
...
}
# Related topics
- Effective Go (opens new window).
- Opinionated Styleguide for the Go language (opens new window).
- We use Swagger to document the API, Swag (opens new window) is recommended.