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.

Golang REST API Boilerplate

This project uses:

The general setup is that:

  1. DB setup is done in /db* directory and connection is established in main.go
  2. Routing is done in main.go
  3. All business logic is handled in /repository/* directory and exposed as interface in /repository/repository.go file
  4. Middlewares are defined in /middleware directory
  5. Models are defined in /models directory
  6. 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!