The goal of this template is to create a solid starting point for a Go backend.
This template will give you a basic structure including an example todo-app that implements the following things:
- A lightweight router with go-chi/chi
- Generation of swagger docs with swaggo/swag and swaggo/http-swagger
- Request validation with go-playground/validator
- Migration of a PostgreSQL DB with pressly/goose
- Generation of type-safe interfaces from SQL with sqlc-dev/sqlc with the jackc/pgx driver
- Management of environment variables with jogo/godotenv
- Automation of some tasks with a Makefile and Docker
This template is far from perfect. I am not an experienced Go developer. I am open for suggestions!
To run the example, follow these steps:
- Run
go mod tidy
. - Make a copy of
.env.example
with the name.env
. - Set the required environment variables.
- Run
make run-postgres
(In the Makefile, set DOCKER_CLIENT to podman if you're using podman). - Run
make apply-migrations
. - Run
go run cmd/api/main.go
.
The documentation is now accessible at http://localhost:3000/swagger/.
If you think that the example code is bloated then you are probably right...
...but I wanted to showcase as much as possible in terms of what is achievable with this stack and how to implement it.
There are Users and Todos. A User can create a Todo and Users can be assigned to Todos.
Updates to the documentation on this templates will follow soon