* Fix language in backend.md * Update contribute/style-guides/backend.md Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
1.7 KiB
Backend style guide
Grafana's backend has been developed for a long time with a mix of code styles. This guide explains how we want to write Go code in the future.
Unless stated otherwise, use the guidelines listed in the following articles:
Linting and formatting
To ensure consistency across the Go codebase, we require all code to pass a number of linter checks.
We use the standard following linters:
In addition to the standard linters, we also use:
- revive with a custom config
- GolangCI-Lint
- gosec
To run all linters, use the lint-go
Makefile target:
make lint-go
Testing
We value clean and readable code, that is loosely coupled and covered by unit tests. This makes it easier to collaborate and maintain the code.
Tests must use the standard library, testing
. For assertions, prefer using testify.
The majority of our tests uses GoConvey but that's something we want to avoid going forward.
In the sqlstore
package we do database operations in tests and while some might say that's not suited for unit tests. We think they are fast enough and provide a lot of value.