- utilizing Go modules
- light and secure docker image based on 🏔Alpine
- multistage build
- GNU Makefiles
- based on official Go project layout by Go standards
- graceful shutdown 😇
- CLI with urfave/cli
- Logging with logrus
- Automatic reconnecting to dependent services
The project uses Go modules, I suggest to delete the go.mod and go.sum files in the project
root and initiate your own project by the following command
go mod init github.com/account/projectThere are a few things that has to be done to take ownership of the template
- Init your brand new Go module (described above)
- Replace the text "example-service" in the
Dockerfileand theMakefile - Adjust your
ldflags(LINKFLAGS) in Makefile
We use Makefiles to build our project. The Makefile is located in the project root
The template has two commands:
make buildBuilds the service, injects the build times constants to the binary and links the packages. The go tool will do all the above.
make test//TODO
By default the following information is added build time:
SERVICE_NAMEGIT_COMMIT_IDGIT_BRANCHBUILD_TIMESTAMP
The above variables can be used in health-checks, microservice debugging or service discover...
You can add more build time constants in the makefile. Make sure that you are adding the build time constant to the correct file.
We are using a multistage build pattern
for security and for small image size as well.
Our builder image is based on golang:1.13 and our service image is alpine:latest.
To run your service use:
./example-service startTo get help
./example-service --help We are using https://github.com/urfave/cli for the service CLI. CLI flags are configured in the service file.
You can add your business logic here
By default the service is listening for SIGTERM signals from the OS. If one occurs a graceful
shutdown is initialized. You can extend the graceful shutdown process in the
handleShutdownGracefully function inside the service main file.
Logging is currently done with github.com/sirupsen/logrus