Skip to content

jcmoro/microservice-go

Repository files navigation

MyService - Example Base Microservice in Go with Gin

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.


📦 Project Structure

.
├── main.go
├── main_test.go
├── go.mod
├── go.sum
├── Dockerfile
├── docker-compose.yml
├── Makefile
└── .env

⚙️ Port Configuration

The port is defined in the .env file at the root of the project:

PORT=8088

If .env does not exist, the service will use port 8088 by default.


🚀 Available Make Commands

Run make help to see all options:

make help

Some 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

🐣 Docker

Build Docker Image

make docker-build

Run Container

make docker-run

Logs can be followed with:

make docker-logs

⚠️ All required dependencies (jq, curl) are already installed inside the container.


👙 Docker Compose

Start the Service

make compose-up

Docker Compose will read .env and map the corresponding port.

View Logs

make compose-logs

Stop and Clean

make compose-down

🔧 Endpoints

GET /health

curl http://localhost:8088/health

Example response:

{
  "status": "ok",
  "service": "myservice",
  "version": "1.0.0"
}

POST /concat

curl -X POST http://localhost:8088/concat \
  -H "Content-Type: application/json" \
  -d '{"items":["go","is","awesome"]}'

Example response:

{
  "result": "go-is-awesome"
}

📌 Requirements

  • Go >= 1.24 (for local build)
  • Docker
  • Docker Compose
  • Make

About

Microservicio base en Go con Gin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published