gin-admin
RBAC scaffolding based on GIN + Gorm 2.0 + CASBIN + WIRE (DI).
English | ไธญๆ
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
swagger
documentation
Generate swag init --parseDependency --generalInfo ./cmd/${APP}/main.go --output ./internal/app/swagger
# Or use Makefile: make swagger
wire
to generate dependency injection
Use wire gen ./internal/app
# Or use Makefile: make wire
gin-admin-cli tool to quickly generate modules
Use thetask.yaml
Create template file: 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;"
generate
command
Execute 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
MIT License
Copyright (c) 2021 Lyric