Skip to content

mikeblum/golang-project-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

17 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

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/

About

starter for building golang projects ๐Ÿšง ๐Ÿ—๏ธ

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published