Sign inSign up

carfdev/go-microservice

By carfdev

โ€ขUpdated over 1 year ago

Go microservice with multi-arch support (amd64 & arm64)

Image
API management
0

109

carfdev/go-microservice repository overview

โ Invoice Microservice

This is a simple invoice microservice built in Go, using:

  • โœ… Hexagonal architecture (also known as Ports & Adapters)
  • ๐Ÿ“จ NATS as the communication protocol (no HTTP)
  • ๐Ÿ›ข๏ธ PostgreSQL as the database
  • ๐Ÿ’พ GORM as the ORM
  • ๐Ÿณ Built with a multi-stage Dockerfile, outputting a minimal binary-only container
  • ๐Ÿงช Easily testable via the NATS CLI

โ ๐Ÿš€ Features

  • Create, read, update and delete invoices via NATS
  • UUID-based primary keys
  • Error responses in JSON format with status codes
  • Environment-based configuration (no hardcoded URLs)

โ ๐Ÿ› ๏ธ Configuration

Environment variables required:

VariableDescription
NATS_URL.NATS server URL (e.g. nats://localhost:4222)
DATABASE_URLPostgreSQL URL (e.g. postgresql://postgres:secret@localhost:5432/invoices)
APP_ENVApplication environment: development or production (default is development)

You can set them in your shell or via Docker -e flags.


โ ๐Ÿณ Running with Docker

Run the container:

docker run -d   --name invoice-service   --network host   -e NATS_URL=nats://localhost:4222   -e DATABASE_URL="postgresql://postgres:secret@localhost:5432/invoices"  -e APP_ENV=production   invoice-ms

โ ๐Ÿงช Testing with NATS CLI

โ Create Invoice
nats request invoice.create '{"amount": 199.99, "customer": "John Doe"}'
โ Get Invoice by ID
nats request invoice.get '{"id": "your-uuid-here"}'
โ Get All Invoices
nats request invoice.get_all ''
โ Update Invoice
nats request invoice.update '{"id": "your-uuid-here", "amount": 299.99, "customer": "Jane Doe"}'
โ Delete Invoice
nats request invoice.delete '{"id": "your-uuid-here"}'

โ โœจ License

MIT License.

Tag summary

Content type

Image

Digest

sha256:a50e5f504โ€ฆ

Size

7.9 MB

Last updated

over 1 year ago

docker pull carfdev/go-microservice