This is a boilerplate backend service using go-micro
.
Goal for this project is to create a good starting-point for new microservices - batteries included.
Currently the project is under heavy development and may change at any time. Feel free to contribute.
If you do not need to use RPCs, I will also provide a boilerplate project for go-web
All you need to do is to checkout this repo and start hacking. But for the sake of simplicity let's just walk through all steps required to customize the template.
- Adjust
DOCKER_IMAGE
andDOCKER_TAG
in the Makefile to your needs - Create your own protobuf definitions and place them inside a folder in
proto/
- Adjust the
proto
command in the Makefile to matchgo_out
to your protobuf setup - Change the service name inside
main.go
- Create the handler(s) you need inside
handler/
and register them inmain.go
Although the target-platform is Kubernetes, we can omit it for local development and only require docker to be setup.
The deploy/docker-compose.dev.yml
file contains all services required for local development (consul, micro, mysql, etc.)
You can either start them normally or use the provided Makefile with make start-local
and make stop-local
.
Once started, you will have a running consul on localhost:8500
as well as the micro-api running on localhost:8080
in rpc mode.
Running and building the service is completely taken care of by the Makefile. One thing to keep in mind is that the service is configured
to run in kubernetes-native mode. Thus you will need to tell it that we are running without K8s by setting the environment variable ENVIRONMENT=local
To run your service then, use make run
and to build a statically linked binary use make build
It's just as easy to build a docker image, just use make docker
and make docker-run
to start the container (Note: The container is started in host-network mode).
The boilerplate ships with configured deploy/k8s/deployment.yaml
and deploy/k8s/service.yaml
which you can use to deploy the service into your Kubernetes cluster.
The boilerplate is preconfigured using go-config. It has two sources attached: file and env (in that order). This means that you can always overwrite configuration defaults provided by the config.json by setting environment variables accordingly.
For example: It might be a good idea to change the log-format when deploying to your cluster. The current default is text which is meant for development.
To change it to JSON logs, either change the config file or just overwrite it by setting LOG_FORMAT=json
.