Golang REST API
Simple, structured, easy to use and new commer friendly golang REST API project.
Architecture
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.
Configuration
Application configuration is in config/config.example.yml
, rename it to config.yml
before you proceed.
Database Migration
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.
Create Migration
# To Create new db migration.
make migrate:create
Run Migration
# 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.
Docker
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.