A small Go microservices example made up of a broker service, an authentication service, and a simple frontend used to exercise the APIs.
This repository demonstrates a basic service-to-service flow:
- The frontend sends a request to the broker service.
- The broker service routes authentication requests to the auth service.
- The auth service validates the user against PostgreSQL and returns the result.
- Location:
./front-end - Purpose: serves a test page with buttons that call the broker endpoints
- Default port:
80
- Location:
./broker-service - Purpose: entry point for API requests and request routing
- Default port:
8002on the host (80in the container) - Key endpoints:
POST /health-style broker testPOST /handlerequest dispatcher
- Location:
./auth-service - Purpose: validates user credentials against PostgreSQL
- Default port:
8081on the host (80in the container) - Key endpoint:
POST /authentication
- PostgreSQL runs through Docker Compose and is used by the auth service.
go-micro/
├── auth-service/
├── broker-service/
├── front-end/
├── project/
│ ├── Makefile
│ └── docker-compose.yml
└── request.http
Install the following before starting:
- Go 1.19 or newer
- Docker and Docker Compose
- GNU Make
From ./project, run:
make up_buildThis target:
- builds the broker binary
- builds the auth binary
- starts the broker, auth service, and PostgreSQL with Docker Compose
To stop the containers later:
make downFrom ./project, run:
make startThis builds the frontend binary and starts the web server locally.
To stop the frontend:
make stopVisit:
http://localhost
Use the page buttons to test:
- broker connectivity
- authentication flow through the broker
The auth service expects a PostgreSQL database named users and a users table with columns used by the application, including:
idemailfirst_namelast_namepassworduser_activecreated_atupdated_at
The frontend currently posts demo credentials defined in ./front-end/cmd/web/templates/test.page.gohtml when the Test Auth button is clicked.
Make sure your local database contains a matching user record, or update the frontend template to use credentials that exist in your local environment.
Run these from ./project:
make build_broker
make build_auth
make build_front
make up
make up_build
make down
make start
make stopYou can also test the broker directly:
POST http://localhost:8002And submit an authentication request:
POST http://localhost:8002/handle
Content-Type: application/json
{
"action": "auth",
"auth": {
"email": "your-user@example.com",
"password": "<your-password>"
}
}- If the auth service cannot connect, confirm PostgreSQL is running and reachable from Docker Compose.
- If authentication fails, verify the user exists in the database and the password matches.
- If the frontend does not load, confirm nothing else is already using port
80.