Go application boilerplate and example applying modern practices
This repository tries to collect the best practices of application development written in Go language. In addition to the language specific details, it also implements language independent practices.
Some of the areas Modern Go Application touches:
- architecture
- package structure
- building the application
- testing
- configuration
- running the application (eg. Docker)
- developer environment/experience
- instrumentation
To help adopting these practices, this repository also serves as a boilerplate for new applications.
- graceful restart (using cloudflare/tableflip) and shutdown
- support for multiple server/daemon instances (using oklog/run)
- metrics and tracing using Prometheus and Jaeger (via OpenCensus)
- logging (using goph/logur and sirupsen/logrus)
- health checks (using InVisionApp/go-health)
- configuration (using spf13/viper)
- messaging (using ThreeDotsLabs/watermill)
- and many more
To create a new application from the boilerplate clone this repository (if you haven't done already) and execute the following:
chmod +x init.sh && ./init.sh
? Package name (github.com/sagikazarmark/modern-go-application)
? Project name (modern-go-application)
? Binary name (modern-go-application)
? Service name (modern-go-application)
? Friendly service name (Modern Go Application)
? Remove init script (y/N) y
It updates every import path and name in the repository to your project's values. Review and commit the changes.
To test or demonstrate the application it comes with a simple load generation tool. You can use it to test the example endpoints and generate some load (for example in order to fill dashboards with data).
Follow the instructions in etc/loadgen.
See INSPIRATION.md for links to articles, projects, code examples that somehow inspired me while working on this project.
The MIT License (MIT). Please see License File for more information.