Gin Boilerplate

The fastest way to deploy a restful api's with Gin Framework with a structured project that defaults to PostgreSQL database and JWT authentication middleware stored in Redis
Alternatives To Gin Boilerplate
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Mall70,266
7 days ago38apache-2.0Java
mall项目是一套电商系统,包括前台商城系统及后台管理系统,基于SpringBoot+MyBatis实现,采用Docker容器化部署。 前台商城系统包含首页门户、商品推荐、商品搜索、商品展示、购物车、订单流程、会员中心、客户服务、帮助中心等模块。 后台管理系统包含商品管理、订单管理、会员管理、促销管理、运营管理、内容管理、统计报表、财务管理、权限管理、设置等模块。
Eladmin20,075
a month ago4apache-2.0Java
eladmin jpa 版本:项目基于 Spring Boot 2.6.4、 Jpa、 Spring Security、Redis、Vue的前后端分离的后台管理系统,项目采用分模块开发方式, 权限控制采用 RBAC,支持数据字典与数据权限管理,支持一键生成前后端代码,支持动态路由
Go Gin Example6,30953 months ago1February 02, 201944mitGo
An example of gin
Go Gin Api4,801
3 months ago23November 28, 202131mitGo
基于 Gin 进行模块化设计的 API 框架,封装了常用功能,使用简单,致力于进行快速的业务研发。比如,支持 cors 跨域、jwt 签名验证、zap 日志收集、panic 异常捕获、trace 链路追踪、prometheus 监控指标、swagger 文档生成、viper 配置文件解析、gorm 数据库组件、gormgen 代码生成工具、graphql 查询语言、errno 统一定义错误码、gRPC 的使用、cron 定时任务 等等。
Blog.core4,498
a month ago23February 05, 20234apache-2.0C#
💖 ASP.NET Core 6.0/7.0 全家桶教程,前后端分离后端接口,vue教程姊妹篇,官方文档:
Xboot3,695
4 months ago8gpl-3.0Java
基于Spring Boot 2.x的一站式前后端分离快速开发平台XBoot 微信小程序+Uniapp 前端:Vue+iView Admin 后端:Spring Boot 2.x/Spring Security/JWT/JPA+Mybatis-Plus/Redis/Elasticsearch/Activiti 分布式限流/同步锁/验证码/SnowFlake雪花算法ID 动态权限 数据权限 工作流 代码生成 定时任务 社交账号 短信登录 单点登录 OAuth2开放平台 客服机器人 数据大屏 暗黑模式
Lilishop3,677
5 days ago3agpl-3.0Java
商城 JAVA电商商城 多语言商城 uniapp商城 微服务商城
Learning_tools2,963
3 months ago38January 05, 2022apache-2.0Go
Go 学习、Go 进阶、Go 实用工具类、Go DDD 项目落地、Go-kit 、Go-Micro 、Go 推送平台、微服务实践
Nodejs Backend Architecture Typescript2,349
2 months ago12apache-2.0TypeScript
Node.js Backend Architecture Typescript - Learn to build a backend server for production ready blogging platform like Medium and FreeCodeCamp. Main Features: Role based, Express.js, Mongoose, Redis, Mongodb, Joi, Docker, JWT, Unit Tests, Integration Tests.
Cool Admin Midway2,06933 days ago68April 02, 202257mitTypeScript
🔥 cool-admin(midway版)一个很酷的后台权限管理框架,模块化、插件化、CRUD极速开发,永久开源免费,基于midway.js 3.x、typescript、typeorm、mysql、jwt、vue3、vite、element-ui等构建
Alternatives To Gin Boilerplate
Select To Compare


Alternative Project Comparisons
Readme

alt tag

License GitHub release (latest by date) Go Version DB Version DB Version

Build Status Go Report Card

Join the chat at https://gitter.im/Massad/gin-boilerplate

Welcome to Golang Gin boilerplate v2

The fastest way to deploy a restful api's with Gin Framework with a structured project that defaults to PostgreSQL database and JWT authentication middleware stored in Redis

Configured with

  • go-gorp: Go Relational Persistence
  • jwt-go: JSON Web Tokens (JWT) as middleware
  • go-redis: Redis support for Go
  • Go Modules
  • Built-in Custom Validators
  • Built-in CORS Middleware
  • Built-in RequestID Middleware
  • Feature PostgreSQL 12 with JSON/JSONB queries & trigger functions
  • SSL Support
  • Enviroment support
  • Unit test
  • And few other important utilties to kickstart any project

Installation

$ go get github.com/Massad/gin-boilerplate
$ cd $GOPATH/src/github.com/Massad/gin-boilerplate
$ go mod init
$ go install

You will find the database.sql in db/database.sql

And you can import the postgres database using this command:

$ psql -U postgres -h localhost < ./db/database.sql

Tip:

You will find that we added 2 trigger functions to the dabatase:

  • public.created_at_column()
  • public.update_at_column()

Those are added to the updated_at and created_at columns to update the latest timestamp automatically in both user and article tables. You can explore the tables and public schema for more info.

Running Your Application

Rename .env_rename_me to .env and place your credentials

$ mv .env_rename_me .env

Generate SSL certificates (Optional)

If you don't SSL now, change SSL=TRUE to SSL=FALSE in the .env file

$ mkdir cert/
$ sh generate-certificate.sh

Make sure to change the values in .env for your databases

$ go run *.go

Building Your Application

$ go build -v
$ ./gin-boilerplate

Testing Your Application

$ go test -v ./tests/*

Import Postman Collection (API's)

Download Postman -> Import -> Import From Link

https://www.postman.com/collections/7f941b400a88ddd9c137

Includes the following:

  • User
    • Login
    • Register
    • Logout
  • Article
    • Create
    • Update
    • Get Article
    • Get Articles
    • Delete
  • Auth
    • Refresh Token

In Login request in Tests tab:

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);

    var jsonData = JSON.parse(responseBody);
    pm.globals.set("token", jsonData.token.access_token);
    pm.globals.set("refresh_token", jsonData.token.refresh_token);

});

It captures the access_token from the success login in the global variable for later use in other requests.

Also, you will find in each request that needs to be authenticated you will have the following:

Authorization -> Bearer Token with value of {{token}}

It's very useful when you want to test the APIs in Postman without copying and pasting the tokens.

On You

You will need to implement the refresh_token mechanism in your application (Frontend).

We have the /v1/token/refresh API here to use it.

For example:

If the API sends 401 Status Unauthorized, then you can send the refresh_token that you stored it before from the Login API in POST /v1/token/refresh to receive the new access_token & refresh_token and store them again. Now, if you receive an error in refreshing the token, that means the user will have to Login again as something went wrong.

That's just an example, of course you can implement your own way.

Version 1

No longer supported

You will find the last update on v1 in v1-session-cookies-auth branch or v1.0.5 release that supported the authentication using the session and cookies stored in Redis if needed.

  • RedisStore: Gin middleware for session management with multi-backend support (currently cookie, Redis).

Contribution

You are welcome to contribute to keep it up to date and always improving!

If you have any question or need help, drop a message at https://gitter.im/Massad/gin-boilerplate

Credit

The implemented JWT inspired from this article: Using JWT for Authentication in a Golang Application worth reading it, thanks Victor Steven


License

(The MIT License)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Popular Redis Projects
Popular Jwt Projects
Popular Data Storage Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Golang
Database
Postgresql
Redis
Rest Api
Microservices
Jwt
Ssl
Postman
Gin
Boilerplate Template
Postman Collection