Go API Boilerplates - gin/minimum
This is a minimum example of Go API with gin-gonic/gin.
A full list of libraries used can be found in Dependencies section.
Table of Contents
Development
This project can be booted up either
- natively with Go installed locally (assuming dependencies like PostgresSQL, Redis, etc. also exist)
- or by Docker Compose (PostgreSQL, Redis, etc. are included out of the box)
Please refer to Makefile or docker-compose.yml for details.
By default, the server will run at http://localhost:3333, but everything is configurable via .env file.
Some common development tools are introduced for better local development experience.
go install github.com/cosmtrek/air@latest
go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
go install github.com/swaggo/swag/cmd/swag@latest
Alternatively, use make install
to install the required Go tooling locally.
Documentation
This service has integrated swaggo/swag to create OpenAPI documentation automatically.
Use command make generate/api
or swag init
to run the generation.
Then navigate to http://localhost:3333/swagger/index.html to view the API documentation.
Dependencies
API
- gin-gonic/gin - Gin is a HTTP web framework written in Go (Golang).
- joho/godotenv - A Go port of Ruby's dotenv library (Loads environment variables from .env files)
- sethvargo/go-envconfig - A Go library for parsing struct tags from environment variables.
- uber-go/zap - Blazing fast, structured, leveled logging in Go.
- swaggo/gin-swagger - gin middleware to automatically generate RESTful API documentation with Swagger 2.0.
Testing
- stretchr/testify - A toolkit with common assertions and mocks that plays nicely with the standard library