Go API Boilerplates - gin/auth-jwt
This is a basic example of Go API
with gin-gonic/gin, PostgreSQL and GORM.
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 swagg
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)
- spf13/viper - Go configuration with fangs
- uber-go/zap - Blazing fast, structured, leveled logging in Go.
- go-ozzo/ozzo-validation - An idiomatic Go (golang) validation package. Supports configurable and extensible validation rules (validators) using normal language constructs instead of error-prone struct tags.
- swaggo/gin-swagger - gin middleware to automatically generate RESTful API documentation with Swagger 2.0.
- dlclark/regexp2 - A full-featured regex engine in pure Go based on the .NET engine
- golang-jwt/jwt - Golang implementation of JSON Web Tokens (JWT).
Database
- PostgreSQL - The World's Most Advanced Open Source Relational Database
- go-gorm/gorm - The fantastic ORM library for Golang, aims to be developer friendly
Testing
- stretchr/testify - A toolkit with common assertions and mocks that plays nicely with the standard library
- ory/dockertest - Write better integration tests! Dockertest helps you boot up ephermal docker images for your Go tests with minimal work.