Go Backend Sample. It’s suitable as a starting point for a REST-API Go application.
This example uses:
- chi for HTTP router;
- kong for building neat commands;
- PostgreSQL as a database and pgx as a driver;
- testify and mock for tests;
- ozzo-validation for request validation;
- slog as a logger;
- the Clean Architecture as the primary approach.
Features:
- Modular Project Structure.
- Built-in migration handling.
- Ready to go example with tests and mocks.
- Easy-to-go Docker deployment.
go-sample
├── 📁 commands/ // Sub-commands for CLI (stands for Command Line Interface).
├── 📁 internal/ // Internal packages for the application according to Go convention.
│ ├── 📁 business/ // Business logic of the application.
│ │ └── 📁 snippets/ // A specimen business-logic package “snippets” with REST-API for snippets creating, listing, and deleting.
│ └── 📁 infrastructure/ // Infrastructure code of the application.
│ ├── 📁 api/ // API-related utilities: middlewares, authentication, error handling for the transport layer.
│ ├── 📁 kongflag/ // Helper package for Kong CLI.
│ ├── 📁 nopslog/ // No-operation logger for tests.
│ ├── 📁 postgres/ // PostgreSQL-related utilities.
│ │ ├── 📁 pgmigrator/ // PostgreSQL migration utilities.
│ │ └── 📁 pgtest/ // PostgreSQL test utilities.
│ ├── 📁 service/ // Service-related reusable code: error handling for the service layer, etc.
│ └── 📁 utils/
│ └── 📁 testutils/ // Test utilities.
├── 📁 migrations/ // This folder contains *.sql migrations.
└── main.go // Entry point for the application.
git clone https://github.com/titusjaka/go-sample
docker-compose up --build
- Return verbose API errors with exact fields in it:
{ "errors": { "title": "Title must not be empty", "expires_at": "Expires at must be within range 1-365 days" } }
- Add user authentication + session storage.
- Add
/status
handler with service health.