How microservices-demo/payment works
Purpose and lifecycle
This deprecated Go microservice exposes payment authorization for the microservices-demo system. It runs as a standalone HTTP process or container, listens on port 8080 internally (mapped to 8082 by Compose), and returns a simple authorization result rather than integrating with a real payment processor.
Entry point: cmd/paymentsvc/main.go.
Process composition
Application dependencies are assembled through explicit wiring, separating startup/configuration from business behavior and HTTP delivery:
• cmd/paymentsvc/main.go
• wiring.go
• service.go
Startup constructs the service, transport, and logging, then starts the HTTP server. This is a single-process, stateless service with no persistence layer evident in the repository.
Payment domain service
The core payment authorization behavior belongs behind the service layer. HTTP handlers should depend on this interface/implementation boundary rather than embed authorization logic directly.
• service.go
• service_test.go
The primary operation accepts a payment request containing an amount and produces an authorization decision. The README example indicates successful authorization is returned as {"authorised":true}.
HTTP transport and API boundary
The HTTP adapter owns routing, JSON request decoding/response encoding, and health exposure. It is the external boundary consumed by other demo services and clients.
• transport.go
• endpoints.go
• api-spec/payment.json
Key public endpoints are POST /paymentAuth and GET /health. The OpenAPI-style contract in api-spec/payment.json is the authoritative API-facing artifact; api-spec/hooks.js supports API-contract test behavior.
Endpoint layer
Endpoints sit between transport and domain service, adapting HTTP-facing request/response shapes to service calls and centralizing endpoint-level error/result handling.
• endpoints.go
• service.go
• transport.go
Control flow is: incoming HTTP request → route/transport decode → endpoint invocation → payment service → encoded HTTP response. Health requests remain operational concerns at the transport/endpoint boundary rather than payment authorization flow.
Observability
Structured logging is configured as a cross-cutting concern and used during startup and request/service execution.
• logging.go
• cmd/paymentsvc/main.go
No metrics, tracing client, database, message broker, or external payment gateway implementation is represented. docker-compose-zipkin.yml suggests optional Zipkin-oriented local infrastructure, but the core service remains independently runnable.
Delivery and runtime packaging
The service targets native Go execution and Docker deployment. Compose provides local service exposure; production/release images are separately defined.
• docker-compose.yml
• docker/payment/Dockerfile
• docker/payment/Dockerfile-release
CI is defined in .github/workflows/main.yml and legacy Travis configuration. Contract/integration testing is container-oriented under test/, including Dredd API-spec validation, while Go tests validate service/component behavior.
Main entry points: transport.go HTTP transport · wiring.go Dependency wiring · main.go HTTP server · endpoints.go Endpoint layer
Components 14
Runtime
- Service entrypoint · Starts the standalone HTTP process.
cmd/paymentsvc/main.go - Dependency wiring · Assembles service, transport, and logging.
wiring.go - Structured logging
logging.go - HTTP server · Listens on port 8080 in the container.
cmd/paymentsvc/main.go
Application
- Endpoint layer · Adapts API requests and centralizes results and errors.
endpoints.go - Payment service · Authorizes a payment amount and returns an authorization decision.
service.go
HTTP API
- HTTP transport · Owns routes, JSON decoding, and response encoding.
transport.go - POST /paymentAuth
transport.go - GET /health · Operational health endpoint.
transport.go - Payment API contract · Authoritative public API artifact.
api-spec/payment.json
Delivery
- Compose deployment · Maps the service container to port 8082.
docker-compose.yml - Service image · Container packaging for local deployment.
docker/payment/Dockerfile - Release image · Production or release image definition.
docker/payment/Dockerfile-release - CI workflow
.github/workflows/main.yml
Connections 16
- Service entrypoint → Dependency wiring: initializes
- Dependency wiring → Structured logging: configures
- Dependency wiring → Payment service: constructs
- Dependency wiring → HTTP transport: constructs
- Service entrypoint → HTTP server: starts
- HTTP server → HTTP transport: serves
- HTTP transport → POST /paymentAuth: routes
- HTTP transport → GET /health: routes
- POST /paymentAuth → Endpoint layer: invokes
- Endpoint layer → Payment service: authorizes payment
- GET /health → Endpoint layer: checks health
- Payment API contract → HTTP transport: defines API boundary
- Compose deployment → Service image: builds or runs
- Service image → HTTP server: packages
- Release image → HTTP server: packages
- CI workflow → Payment API contract: validates