Skip to content

matthiassommer/golang-gateway-microservice-template

Repository files navigation

Golang Gateway Microservice Template

Exemplary Golang implementation of a Gateway Microservice.

Go Report Card

Overview

The microservice gateway proxies incoming HTTP requests to subsequent microservices. It is the single entry point for the backend. The gateway can be extended with middlewares (for authentication, authorisation, etc.)

  • Reverse proxy to internal microservices
  • Flexible configuration
  • Echo HTTP router
  • Middlewares for proxy functionality and more
  • Mock creation of interfaces with Mockery
  • API documentation with Swagger UI and go-swagger
  • Code linting with GolangCI

Run the microservice

To run the server, follow these simple steps:

go run main.go

To run the server in a docker container

docker build -t gateway-service .

Once image is built use

docker run --rm -it gateway-service

Swagger specification

  1. Download the latest release of go-swagger

  2. Generate the Swagger specification with

    %GOPATH%/bin/go-swagger generate spec --scan-models -o ./swaggerui/swagger.json
  3. The interactive Swagger documentation is available via the /swagger endpoint.

Environment variable

API_VERSION: the version parameter in the endpoint urls

Launch.json contains a debug launch configuration. Environment parameters can be specified in a local.env file.

Linting

Install the linter runner GolangCI-Lint. The config file is already part of this repository.

Unit tests and mocks

Mockery is used to generate mocks from interfaces for unit tests.

%GOPATH%/bin/mockery -all -case=underscore -inpkg

Run all tests:

go test ./...

About

Template for a microservice gateway in Golang

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published