When starting a new project in a technology that you don’t know very well having a small boilerplate that shows how basic stuff work together is very nice to have.
Also all projects have some common things such as user profiles, authentication, database, logging etc.
Here is a small boilerplate for such things in Golang.
More detailed guide on how to get this working is on the project site.
This project uses:
- Chi router for routing
- Pure go Postgres driver for DB connection
- Golang migrate for DB migrations
- Docker for running postgres
The general setup is that:
- DB setup is done in
/db*directory and connection is established in
- Routing is done in
- All business logic is handled in
/repository/*directory and exposed as interface in
- Middlewares are defined in
- Models are defined in
- REST endpoints are defined in
api/v1/*directory and endpoints are only responsible in decoding JSON and passing it to specific repository and sending JSON responses to requests
Hope it helps somebody to setup their golang project!