Skip to content
/ golang-http-service Public template

Template for creating HTTP service

License

Notifications You must be signed in to change notification settings

slamdev/golang-http-service

Repository files navigation

golang-http-service

Template for creating HTTP service

Components

HTTP API

API is defined in OpenAPI 3 format in the openapi.yaml file. DTOs and service interface code is generated using oapi-codegen.

HTTP server

Echo framework is used to manage routes. API generator has a nice integration with this framework.

Configuration

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:

  1. application.yaml
  2. application-cloud.yaml
  3. 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.

Observability

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.

Testing

For reach assertions the testify library is used. Mock are generated via golang mock tool.

Linting

vacuum is used to lint OpenAPI files and golangci-lint for Go files.

Building

All the build process is describe it the (Makefile)[Makefile]. Run make build to test and build the binary.

Deployment

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.

About

Template for creating HTTP service

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published