This is a monolithic http api starter with sane defaults. Features include:
air
- hot-reloading dev serverslog
- global loggingchi/v5
- routing & middlewarepgx/v5
- database connectivity with poolinggoose
- database migrations without adding to app dependencybcrypt
- password hashinggolang-jwt/jwt/v5
- jwt Authenticationvalidator/v10
- incoming request payload validationenvconfig
- app configuration parsing & validationprometheus/promhttp
for default metricsMakefile
commands for toolchain
The project follows below folder structure:
project-root/
├── api/ # API-related code (e.g. REST)
│ ├── middleware/ # Middleware for HTTP requests
│ │ └── ...
│ ├── routes.go # All Application routes
│ └── server.go # Server Setup
├── app/ # Encapsulted Applicaton Logic
│ ├── auth/
│ │ ├── handler.go # Http handlers specific to auth
│ │ ├── router.go # Http routes specific to auth
│ │ └── types.go # Types routes specific to auth
│ └── ... # Other application logic folders
├── cert/ # Certificates & Keys
│ └── ...
├── cmd/
│ ├── main.go # Server entrypoint
│ └── ... # Other application entrypoints
├── config/ # Configuration logic
│ ├── config.go
│ └── ...
├── db/
│ ├── migrations/ # Migrations files for goose
│ │ └── *.sql
│ ├── db.go # Database connection setup
│ ├── logger.go # Database logger adapter
│ └── ... # Database model files
├── docs/ # Project documentations
│ ├── bruno/ # Bruno collection for exploring api
│ │ └── ...
│ └── ...
├── pkg/ # Public, reusable packages
│ ├── <name>/
│ │ └── ... # Public package code
│ └── ...
├── .gitignore # Gitignore file
├── Makefile # Runnable Scripts
├── go.mod # Go module file
├── go.sum # Go module dependencies file
└── README.md # Project README
use below command to build binaries targetted towards supported os
& architechture
. A github workflow file is also included
make build os=<OPERATING SYSTEM> arch=<ARCHITECHTURE>
Ensure following tools available in your machine
- Docker >= v27
- Docker Compose >=v2.29
- OpenSSL >= 1.1.1
To run the development server use below command:
make init
This command will
- Copy
.env.example
to.env
, filling in default values - Generate TLS cert for serving https locally.
- Generate ECDSA public-private key pair for JWT Auth locally.
- Start development server in hot reload mode
- Migrate database to latest migration
After running above command for the first time, you should only start development server in hot reload mode using below command
make dev
n.b. In production environment, mount your certificates in cert
directory, ensure proper name & path supplied in env.
Bruno is an Opensource IDE For Exploring and Testing Api's, lightweight alternative to postman/insomnia. Open Directory docs/bruno
from the bruno app & the collection will show up. Choose the environment Local
.
Download & install bruno -> click here.
install & clean golang dependencies
make tidy
make deps
run the development server with hot reload
make dev
run migration of postgresql database, ensure .env
values are correctly given
make migrate-up
revert migrations by 1 level
make migrate-down
create migration files
make migrate-create f=<filename>
Generate TLS cert for serving https locally.
make tls
Generate ECDSA public-private key pair for JWT Auth locally.
make jwt
Run linter
make lint