A RESTful API for the classic Northwind database, built with Go and Gin. This project demonstrates clean architecture, modular design, JWT authentication, and structured logging using zerolog.
- Customer and Employee endpoints (CRUD)
- JWT-based authentication (middleware)
- Swagger/OpenAPI documentation (docs/swagger.yaml)
- Structured logging to
app.log
- Environment-based configuration
- Graceful shutdown
- SQLite database (
northwind.db
)
.
├── main.go
├── go.mod
├── internal/
│ ├── config/ # App config & DB setup
│ ├── handlers/ # HTTP handlers
│ ├── logging/ # Logger setup & middleware
│ ├── middleware/ # Custom Gin middleware
│ ├── models/ # Data models & responses
│ ├── repositories/ # Data access layer
│ ├── routes/ # Route registration
│ ├── server/ # Gin engine setup
│ └── utils/ # Utilities (e.g., JWT)
├── docs/ # Swagger docs
├── northwind.db # SQLite database
├── .env # Environment variables
├── .air.toml # Live reload config
└── tmp/ # Build artifacts
- Go 1.18+
- swag (for Swagger docs)
- SQLite3
-
Clone the repo:
git clone https://github.com/yourusername/northwind-api.git cd northwind-api
-
Copy and edit
.env
:cp .env.example .env # Edit as needed (JWT_SECRET, PORT, etc.)
-
Install dependencies:
go mod tidy
-
Generate Swagger docs:
swag init -g main.go -o ./docs
-
Run the server:
go run main.go # or with live reload (requires air) air
- Swagger UI: http://localhost:8080/docs/index.html
- Health check:
GET /healthz
- Versioned API:
GET /api/v1/...
See internal/config/config.go
for config loading. Main environment variables:
JWT_SECRET
(required)PORT
(default: 8080)DB_PATH
(default: northwind.db)GO_ENV
(default: development)API_VERSION
(default: v1)
- Logs are written to
app.log
using zerolog. - HTTP requests are logged via middleware (
internal/logging/logger.go
).
MIT
See also:
main.go
– Entry pointinternal/routes/routes.go
– Route registrationinternal/config/config.go
– Configurationdocs/swagger.yaml
– OpenAPI spec