golang-project-template
A πbatteries-included Golang project template derived from bootstrapping many Golang projects
GOTO libraries π
pre-commit
: https://pre-commit.com/
A framework for managing and maintaining multi-language pre-commit hooks.
golangci-lint
: https://golangci-lint.run/
Fast linters Runner for Go.
log/slog
:
Stdlib structured, pluggable logging >= Go 1.21.0.
koanf
: https://github.com/knadh/koanf
Simple, lightweight, extensible, configuration management library for Go.
testify
: https://github.com/stretchr/testify
A toolkit with common assertions and mocks that plays nicely with the standard library.
Inspired By π‘
https://github.com/golang-standards/project-layout
π΄ from https://github.com/cloudflare/cloudflare-go/blob/master/.golintci.yaml
π΄ from https://github.com/github/gitignore/blob/main/Go.gitignore
Run It π
go run main.go
Configure It βοΈ
.env
is excluded from git as environment variables can contain credentials and secrets.
vim .env
LOG_LEVEL=debug
LOG_FORMAT=json
or via CLI:
export LOG_FORMAT=json && export LOG_LEVEL=debug && go run main.go
Test It π§ͺ
Test for coverage and race conditions
go test -race -covermode=atomic . /...
Lint It π
pre-commit run --all-files --show-diff-on-failure
Make It βοΈ
make help
Secure It
make vuln
π
With Vulnerability Management for Go scan our proj against the Go vulnerability database.
Fork It π΄
This is a template project for starting your next Golang proj:
How To
fmt.Println
is banned in favor of log/slog
example fmt.Println("Hello, world")
will throw an error running golangci-lint run ./...
or pre-commit
Environment Variables
note: env variable values are case-insensitive ex. LOG_LEVEL=
both INFO
and info
are valid.
Name | Description | Default |
---|---|---|
CONF_PATH |
dotenv-style conf file | ./.env |
LOG_LEVEL |
logging levels: trace ,debug ,info ,warn |
INFO |
LOG_FORMAT |
logging format: json or defaults to plaintext |
TEXT |
Roadmap
Branch for web-based Golang apps with Gin π₯
https://github.com/gin-gonic/gin
Branch for cli-based Golang apps with urfave/cli