https://github.com/flashbots/go-template
Template for Go projects
https://github.com/flashbots/go-template
Last synced: 10 months ago
JSON representation
Template for Go projects
- Host: GitHub
- URL: https://github.com/flashbots/go-template
- Owner: flashbots
- License: mit
- Created: 2022-02-16T16:40:03.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-11-19T07:43:26.000Z (over 1 year ago)
- Last Synced: 2025-03-26T15:21:10.735Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 102 KB
- Stars: 40
- Watchers: 12
- Forks: 6
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-template
[](https://goreportcard.com/report/github.com/flashbots/go-template)
[](https://github.com/flashbots/go-template/actions?query=workflow%3A%22Checks%22)
Toolbox and building blocks for new Go projects, to get started quickly and right-footed!
* [`Makefile`](https://github.com/flashbots/go-template/blob/main/Makefile) with `lint`, `test`, `build`, `fmt` and more
* Linting with `gofmt`, `gofumpt`, `go vet`, `staticcheck` and `golangci-lint`
* Logging setup using the [slog logger](https://pkg.go.dev/golang.org/x/exp/slog) (with debug and json logging options)
* [GitHub Workflows](.github/workflows/) for linting and testing, as well as releasing and publishing Docker images
* Entry files for [CLI](/cmd/cli/main.go) and [HTTP server](/cmd/httpserver/main.go)
* Webserver with
* Graceful shutdown, implementing `livez`, `readyz` and draining API handlers
* Prometheus metrics
* Using https://pkg.go.dev/github.com/go-chi/chi/v5 for routing
* [Urfave](https://cli.urfave.org/) for cli args
* https://github.com/uber-go/nilaway
* Postgres database with migrations
* See also:
* Public project setup: https://github.com/flashbots/flashbots-repository-template
* Repository for common Go utilities: https://github.com/flashbots/go-utils
Pick and choose whatever is useful to you! Don't feel the need to use everything, or even to follow this structure.
For advanced Golang knowledge, tips & tricks, see also https://goperf.dev
---
## Getting started
**Build CLI**
```bash
make build-cli
```
**Build HTTP server**
```bash
make build-httpserver
```
**Install dev dependencies**
```bash
go install mvdan.cc/gofumpt@v0.4.0
go install honnef.co/go/tools/cmd/staticcheck@2024.1.1
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3
go install go.uber.org/nilaway/cmd/nilaway@v0.0.0-20240821220108-c91e71c080b7
go install github.com/daixiang0/gci@v0.11.2
```
**Lint, test, format**
```bash
make lint
make test
make fmt
```
**Database tests (using a live Postgres instance)**
Database tests will be run if the `RUN_DB_TESTS` environment variable is set to `1`.
```bash
# start the database
docker run -d --name postgres-test -p 5432:5432 -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgres postgres
# run the tests
RUN_DB_TESTS=1 make test
# stop the database
docker rm -f postgres-test
```