Simple, structured, easy to use and new commer friendly golang REST API project.
Common Layered architecture with following layers:
Handler/Controller/Delivery
: Responsible for handling incoming HTTP request, parsing request, validating request, calling service layer and sending response.Service/Usecase
: Business logic layer, responsible for handling business logic, calling repository layer and returning response to handler.Repository/Store
: Responsible for handling database operation, query, insert, update, delete etc.
- HTTP router: chi
- Struct validator: validator
- Unique Identifier: uuid
- Postgres driver & pooling: pgx
- Postgres struct scanner: scanny
- Config parser: viper
- Logger: zerolog
- Auth: jwt
- Testing: testify
- Metrics & Instrumentation:
- Prometheus: prometheus
- Grafana: grafana
- CLI:
- Database Migration Tool: goose
- Development live reloading: air
- Linters: golangci-lint
Application configuration is in config/config.example.yml
, rename it to config.yml
before you proceed.
Migration is handled by goose
cli tool. make sure you have installed goose binary in your system. All migrations file is in database/migrations
directory.
# To Create new db migration.
make migrate:create
# To Execute/Run the migration file.
goose -dir database/migrations postgres "host=localhost port=5432 user=<your_username> password=<your_password> dbname=<your_db_name> sslmode=disable" up
Please refer to goose for more detail documentation & instruction.
The metrics and instrumentation are configured to run in Docker, while the main application service runs on the host machine. To build and run the Metrics service using Docker Compose, refer to the commands in the Makefile.