/golang-project-template

starter for building golang projects 🚧 πŸ—οΈ

Primary LanguageGoMIT LicenseMIT

golang-project-template

πŸ’― Go Report Card

Coverage

License: MIT

A πŸ”‹batteries-included Golang project template derived from bootstrapping many Golang projects


golang-helloworld

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 β˜‘οΈ

‼️ ⚠️ make sure .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:

https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template

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

https://github.com/urfave/cli/