All Projects → yakuter → Ugin

yakuter / Ugin

Licence: apache-2.0
UGin is an API boilerplate written in Go (Golang) with Gin Framework.

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Ugin

Golang Gin Realworld Example App
Exemplary real world application built with Golang + Gin
Stars: ✭ 1,780 (+1518.18%)
Mutual labels:  api, gorm, gin, example, boilerplate
Snake
🐍 一款小巧的基于Go构建的开发框架,可以快速构建API服务或者Web网站进行业务开发,遵循SOLID设计原则
Stars: ✭ 615 (+459.09%)
Mutual labels:  api, gorm, gin
Fizz
A Common DSL for Migrating Databases
Stars: ✭ 92 (-16.36%)
Mutual labels:  mysql, sqlite, postgres
Vscode Sqltools
Database management for VSCode
Stars: ✭ 741 (+573.64%)
Mutual labels:  mysql, sqlite, postgres
Prisma
Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite & MongoDB (Preview)
Stars: ✭ 18,168 (+16416.36%)
Mutual labels:  mysql, postgres, sqlite
Rbatis
Rust ORM Framework High Performance Rust SQL-ORM(JSON based)
Stars: ✭ 482 (+338.18%)
Mutual labels:  mysql, sqlite, postgres
Ginbro
Converting a MySQL database'schema to a RESTful golang APIs app in the fastest way
Stars: ✭ 97 (-11.82%)
Mutual labels:  gorm, gin, boilerplate
Go Project Sample
Introduce the best practice experience of Go project with a complete project example.通过一个完整的项目示例介绍Go语言项目的最佳实践经验.
Stars: ✭ 344 (+212.73%)
Mutual labels:  gorm, gin, example
Xorm
Simple and Powerful ORM for Go, support mysql,postgres,tidb,sqlite3,mssql,oracle, Moved to https://gitea.com/xorm/xorm
Stars: ✭ 6,464 (+5776.36%)
Mutual labels:  mysql, sqlite, postgres
Goqu
SQL builder and query library for golang
Stars: ✭ 984 (+794.55%)
Mutual labels:  mysql, sqlite, postgres
East
node.js database migration tool
Stars: ✭ 53 (-51.82%)
Mutual labels:  mysql, sqlite, postgres
Go Gin Example
An example of gin
Stars: ✭ 4,992 (+4438.18%)
Mutual labels:  api, gorm, gin
Express Rest Api Boilerplate
Express REST API with JWT Authentication and support for sqlite, mysql, and postgresql
Stars: ✭ 384 (+249.09%)
Mutual labels:  mysql, sqlite, boilerplate
Electrocrud
Database CRUD Application Built on Electron | MySQL, Postgres, SQLite
Stars: ✭ 1,267 (+1051.82%)
Mutual labels:  mysql, sqlite, postgres
Sqlx
🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, SQLite, and MSSQL.
Stars: ✭ 5,039 (+4480.91%)
Mutual labels:  mysql, sqlite, postgres
Go Gin Api
基于 Gin 进行模块化设计的 API 框架,封装了常用功能,使用简单,致力于进行快速的业务研发。比如,支持 cors 跨域、jwt 签名验证、zap 日志收集、panic 异常捕获、trace 链路追踪、prometheus 监控指标、swagger 文档生成、viper 配置文件解析、gorm 数据库组件、gormgen 代码生成工具、graphql 查询语言、errno 统一定义错误码、gRPC 的使用 等等。
Stars: ✭ 730 (+563.64%)
Mutual labels:  gorm, gin, viper
Duckygo
一个同时支持Session以及JWT的高性能高可用 Golang Restful API 脚手架 !
Stars: ✭ 57 (-48.18%)
Mutual labels:  gorm, mysql, gin
Rdbc
Rust DataBase Connectivity (RDBC) :: Common Rust API for database drivers
Stars: ✭ 328 (+198.18%)
Mutual labels:  mysql, sqlite, postgres
Koa Vue Notes Api
🤓 This is a simple SPA built using Koa as the backend, Vue as the first frontend, and React as the second frontend. Features MySQL integration, user authentication, CRUD note actions, and async/await.
Stars: ✭ 342 (+210.91%)
Mutual labels:  api, mysql, boilerplate
Migrate
Database migrations. CLI and Golang library.
Stars: ✭ 7,712 (+6910.91%)
Mutual labels:  mysql, sqlite, postgres

UGin - Ultimate Gin API

UGin is an API boilerplate written in Go (Golang) with Gin Framework. https://github.com/gin-gonic/gin

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:

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

Default Models

UGin has two models (Post and Tag) as boilerplate to show relational database usage.

/model/post-model.go content:

type Post struct {
	gorm.Model
	Name        string `json:"Name" gorm:"type:varchar(255)"`
	Description string `json:"Description"  gorm:"type:text"`
	Tags        []Tag  // One-To-Many relationship (has many - use Tag's UserID as foreign key)
}

type Tag struct {
	gorm.Model
	PostID      uint   `gorm:"index"` // Foreign key (belongs to)
	Name        string `json:"Name" gorm:"type:varchar(255)"`
	Description string `json:"Description" gorm:"type:text"`
}

Filtering, Search and Pagination

UGin has it's own filtering, search and pagination system. You just need to use these parameters.

Query parameters:

/posts/?Limit=2
/posts/?Offset=0
/posts/?Sort=ID
/posts/?Order=DESC
/posts/?Search=hello

Full: http://localhost:8081/posts/?Limit=25&Offset=0&Sort=ID&Order=DESC&Search=hello

Dependencies

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

go get -u github.com/gin-gonic/gin
go get -u github.com/jinzhu/gorm
go get -u github.com/jinzhu/gorm/dialects/postgres
go get -u github.com/jinzhu/gorm/dialects/sqlite
go get -u github.com/jinzhu/gorm/dialects/mysql
go get -u github.com/spf13/viper

Middlewares

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()
router.Use(gin.Logger())
router.Use(gin.Recovery())

2. CORS Middleware

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

router.Use(include.CORS())

There is also a good repo for this: https://github.com/gin-contrib/cors

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: https://github.com/appleboy/gin-jwt

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

What is next?

  • Ugin needs a user service and an authentication method with JWT.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].