This project is an example base microservice in Go using Gin, exposing the following endpoints:
GET /health→ Checks if the service is running.POST /concat→ Receives a JSON with an array of strings and returns the concatenation of the elements separated by hyphens.
The service is configurable via .env, Docker, and Docker Compose, and all necessary dependencies for testing (jq, curl) are automatically installed inside the container.
.
├── main.go
├── main_test.go
├── go.mod
├── go.sum
├── Dockerfile
├── docker-compose.yml
├── Makefile
└── .env
The port is defined in the .env file at the root of the project:
PORT=8088If .env does not exist, the service will use port 8088 by default.
Run make help to see all options:
make helpSome useful commands:
| Command | Description |
|---|---|
make run |
Runs the service locally (requires Go) |
make build |
Compiles the local binary |
make test |
Tests the /health and /concat endpoints inside the container |
make go-test |
Native Go test with stretchr/testify for /health and /concat inside the container |
make docker-build |
Builds the Docker image |
make docker-run |
Runs the Docker container |
make docker-logs |
Shows container logs |
make compose-up |
Starts the service with Docker Compose |
make compose-logs |
Shows Docker Compose service logs |
make compose-down |
Stops and cleans up containers |
make clean |
Removes binaries and temporary files |
make docker-buildmake docker-runLogs can be followed with:
make docker-logs
⚠️ All required dependencies (jq,curl) are already installed inside the container.
make compose-upDocker Compose will read .env and map the corresponding port.
make compose-logsmake compose-downcurl http://localhost:8088/healthExample response:
{
"status": "ok",
"service": "myservice",
"version": "1.0.0"
}curl -X POST http://localhost:8088/concat \
-H "Content-Type: application/json" \
-d '{"items":["go","is","awesome"]}'Example response:
{
"result": "go-is-awesome"
}- Go >= 1.24 (for local build)
- Docker
- Docker Compose
- Make