• Stars
    star
    2,245
  • Rank 20,508 (Top 0.5 %)
  • Language
    Go
  • License
    MIT License
  • Created about 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A lightweight, flexible, elegant and full-featured RBAC scaffolding based on GIN + GORM 2.0 + Casbin + Wire DI.

gin-admin

RBAC scaffolding based on GIN + Gorm 2.0 + CASBIN + WIRE (DI).

English | ไธญๆ–‡

ReportCard GoDoc License

Features

  • Follow the RESTful API design specification
  • Use Casbin to implement fine-grained access to the interface design
  • Use Wire to resolve dependencies between modules
  • Provides rich Gin middlewares (JWTAuth,CORS,RequestLogger,RequestRateLimiter,TraceID,CasbinEnforce,Recover,GZIP)
  • Support Swagger

Dependent Tools

go get -u github.com/cosmtrek/air
go get -u github.com/google/wire/cmd/wire
go get -u github.com/swaggo/swag/cmd/swag
  • air -- Live reload for Go apps
  • wire -- Compile-time Dependency Injection for Go
  • swag -- Automatically generate RESTful API documentation with Swagger 2.0 for Go.

Dependent Library

  • Gin -- The fastest full-featured web framework for Go.
  • GORM -- The fantastic ORM library for Golang
  • Casbin -- An authorization library that supports access control models like ACL, RBAC, ABAC in Golang
  • Wire -- Compile-time Dependency Injection for Go

Getting Started

git clone https://github.com/LyricTian/gin-admin

cd gin-admin

go run cmd/gin-admin/main.go web -c ./configs/config.toml -m ./configs/model.conf --menu ./configs/menu.yaml

# Or use Makefile: make start

The database and table structure will be automatically created during the startup process. After the startup is successful, you can access the swagger address through the browser: http://127.0.0.1:10088/swagger/index.html

Generate swagger documentation

swag init --parseDependency --generalInfo ./cmd/${APP}/main.go --output ./internal/app/swagger

# Or use Makefile: make swagger

Use wire to generate dependency injection

wire gen ./internal/app

# Or use Makefile: make wire

Use the gin-admin-cli tool to quickly generate modules

Create template file: task.yaml

name: Task
comment: TaskManage
fields:
  - name: Code
    type: string
    required: true
    binding_options: ""
    gorm_options: "size:50;index;"
  - name: Name
    type: string
    required: true
    binding_options: ""
    gorm_options: "size:50;index;"
  - name: Memo
    type: string
    required: false
    binding_options: ""
    gorm_options: "size:1024;"

Execute generate command

gin-admin-cli g -d . -p github.com/LyricTian/gin-admin/v8 -f ./task.yaml

make swagger

make wire

make start

Project Layout

โ”œโ”€โ”€ cmd
โ”‚   โ””โ”€โ”€ gin-admin
โ”‚       โ””โ”€โ”€ main.go       
โ”œโ”€โ”€ configs
โ”‚   โ”œโ”€โ”€ config.toml       
โ”‚   โ”œโ”€โ”€ menu.yaml         
โ”‚   โ””โ”€โ”€ model.conf        
โ”œโ”€โ”€ docs                  
โ”œโ”€โ”€ internal
โ”‚   โ””โ”€โ”€ app
โ”‚       โ”œโ”€โ”€ api           
โ”‚       โ”œโ”€โ”€ config        
โ”‚       โ”œโ”€โ”€ contextx      
โ”‚       โ”œโ”€โ”€ dao           
โ”‚       โ”œโ”€โ”€ ginx          
โ”‚       โ”œโ”€โ”€ middleware    
โ”‚       โ”œโ”€โ”€ module        
โ”‚       โ”œโ”€โ”€ router        
โ”‚       โ”œโ”€โ”€ schema        
โ”‚       โ”œโ”€โ”€ service       
โ”‚       โ”œโ”€โ”€ swagger       
โ”‚       โ”œโ”€โ”€ test          
โ”œโ”€โ”€ pkg
โ”‚   โ”œโ”€โ”€ auth              
โ”‚   โ”‚   โ””โ”€โ”€ jwtauth       
โ”‚   โ”œโ”€โ”€ errors            
โ”‚   โ”œโ”€โ”€ gormx             
โ”‚   โ”œโ”€โ”€ logger            
โ”‚   โ”‚   โ”œโ”€โ”€ hook
โ”‚   โ””โ”€โ”€ util              
โ”‚       โ”œโ”€โ”€ conv         
โ”‚       โ”œโ”€โ”€ hash         
โ”‚       โ”œโ”€โ”€ json
โ”‚       โ”œโ”€โ”€ snowflake
โ”‚       โ”œโ”€โ”€ structure
โ”‚       โ”œโ”€โ”€ trace
โ”‚       โ”œโ”€โ”€ uuid
โ”‚       โ””โ”€โ”€ yaml
โ””โ”€โ”€ scripts               

Contact

wechat qqgroup

MIT License

Copyright (c) 2021 Lyric