Template for creating HTTP service
API is defined in OpenAPI 3 format in the openapi.yaml file. DTOs and service interface code is generated using oapi-codegen.
Echo framework is used to manage routes. API generator has a nice integration with this framework.
Application configuration is defined application.yaml file. There is profiles system
that allows to use and merge multiple configuration files together. It is controlled with ACTIVE_PROFILES
environment variable. E.g.: ACTIVE_PROFILES=cloud,dev
will merge these files together:
- application.yaml
- application-cloud.yaml
- application-dev.yaml
Uber config library is used to parse and merge config files. It also supports environment variables.
Configuration files are embedded into the resulting binary with go embed.
Additionally you can add more configuration files from filesystem by defining APP_CONFIG_ADDITIONAL_LOCATION
env
variable. In this case the app will recursively search for application.yaml
files in that location.
Zap is used to control logs. Logs are outputted in plain text format when the application is running locally and in json format when the cloud profile is used.
Application exposes Prometheus metrics at /metrics endpoint. List of metrics includes basic http stats collected via Echo Prometheus library.
Application exposes health endpoint at /health.
Both prometheus and health endpoints are served on a separate port to make sure it is not exposed to outside world.
For reach assertions the testify library is used. Mock are generated via golang mock tool.
vacuum is used to lint OpenAPI files and golangci-lint for Go files.
All the build process is describe it the (Makefile)[Makefile]. Run make build
to test and build the binary.
Application is distributed via docker container + helm chart. skaffold is used to build and push docker container (with docker-less ko-build) as well as to package and deploy helm chart.