Exemplary Golang implementation of a Gateway Microservice.
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
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
-
Download the latest release of go-swagger
-
Generate the Swagger specification with
%GOPATH%/bin/go-swagger generate spec --scan-models -o ./swaggerui/swagger.json
-
The interactive Swagger documentation is available via the /swagger endpoint.
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.
Install the linter runner GolangCI-Lint. The config file is already part of this repository.
Mockery is used to generate mocks from interfaces for unit tests.
%GOPATH%/bin/mockery -all -case=underscore -inpkg
Run all tests:
go test ./...