Skip to content
UGin is an API boilerplate written in Go (Golang) with Gin Framework.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

UGin - Ultimate Gin API

UGin is an API boilerplate written in Go (Golang) with Gin Framework.

Database Support

UGin uses gorm as an ORM. So Sqlite3, MySQL and PostgreSQL is supported. You just need to edit config.yml file according to your setup.

config.yml content:

  driver: "postgres"
  dbname: "database_name"
  username: "user"
  password: "password"
  host: "localhost"
  port: "5432"


UGin uses Gin for main framework, Gorm for database and Viper for configuration.

go get -u
go get -u
go get -u
go get -u
go get -u
go get -u


1. Logger and Recovery Middlewares

Gin has 2 important built-in middlewares: Logger and Recovery. UGin calls these two in default.

router := gin.Default()

This is same with the following lines.

router := gin.New()

2. CORS Middleware

CORS is really important for API's and UGin has it's own CORS middleware in include/middleware.go. CORS middleware is called with the code below.


There is also a good repo for this:

3. BasicAuth Middleware

Almost every API needs a protected area. Gin has BasicAuth middleware for protecting routes. Basic Auth is an authorization type that requires a verified username and password to access a data resource. In UGin, you can find an example for a basic auth. To access these protected routes, you need to add Basic Authorization credentials in your requests. If you try to reach these endpoints from browser, you should see a window prompting you for username and password.

authorized := router.Group("/admin", gin.BasicAuth(gin.Accounts{
    "username": "password",

// /admin/dashboard endpoint is now protected
authorized.GET("/dashboard", controller.Dashboard)

If you want to use JWT for authorization in UGin, you can check this:

Default Endpoints

Method URI Function
GET /posts/ controller.GetPosts
POST /posts/ controller.CreatePost
GET /posts/:id controller.GetPost
PUT /posts/:id controller.UpdatePost
DELETE /posts/:id controller.DeletePost
GET /admin/dashboard controller.Dashboard

Demonstration and Documentation

I used gencebay's great API request and response mock tool httplive to show the endpoints and responses of UGin. So there is a httplive folder which is including httplive.db. This folder is not necessary for API, you can delete it whenever you want. Just wanted to give you httplive.db that can be used in your local httplive installation.


You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.