Boilerplate API built using Golang: (Gin Framework for routing, Testify for testing, Swagger for Documentation, Viper for configuration, and Go Mod for dependency management). The intention is for this to be used as a starter application to build out a scalable and organized API service. With minimal configuration, this application can be built and deployed in a container using docker. We have done some research and have tried to stick to Golang best practices as much as possible. The routes and testing can be expanded to meet your needs.
- Gin Documentation
- sqlc Documentation
- Testify Documentation
- Swagger Documentation
- Viper Documentation
- Go Mod Documentation
-
Start coding!
You should now be able to start coding. You can start expanding, building, and deploying. You can use make to build/ run your app:
make build make run
A quick look at the top-level files and directories you'll see in this project.
.
├── build/
├── config/
├── docs/
├── internal/
├── sql/
├── Dockerfile
├── docker-compose.yaml
├── Makefile
├── go.mod
├── go.sum
├── main.go
├── sqlc.yaml
├── .gitignore
└── README.md
-
/build
: This directory contains the binary after a build -
/config
: This directory contains the viper configration and the property files. -
/docs
: Directory for swagger files. -
/internal
: This directory contains all the go code for the project. -
/sql
: This directory contains all the sql files for the project (migrations/sqlc queries). -
Dockerfile
: This file contains the buildsteps to build your image using a multi stage build. It is currently using a scratch image to keep it lightweight. -
docker-compose.yaml
: This file contains the docker-compose configurations for easy set-up of a local dev environment. -
Makefile
: This file allows the use of make to run tests, build locally, and is used to build in the pipeline. This can be expanded as needed -
go.mod/go.sum
: These files are generated by Go Mod dependency management and can be learned about in the documentation link provided above. -
main.go
: This file is the starting point for the application, which starts the server. -
sqlc.yaml
: This file is the config file for sqlc, which determines where the .sql code in/sql
gets generated to. -
.gitignore
: This file tells git which files it should not track / not maintain a version history for. -
README.md
: A text file containing useful reference information about your project.
This project uses goose
to manage database migrations. Simply add new migrations into the sql/migrations
folder and run make migrate_up
or make migrate_down
.
- For more specialised use, please refer to
goose
documentation
This project uses sqlc
to generate type-safe golang code from SQL.
- All queries go into the
sql/queries
folder. - Run
sqlc generate
to generate golang code for your SQL queries. All code is generated into theinternal/db/sqlc
folder
There may be further configuration needed as you expand your application.
- Sng Haoren