Gin-Admin
A lightweight, flexible, elegant and full-featured RBAC scaffolding based on GIN + GORM 2.0 + Casbin 2.0 + Wire DI.
English | 中文
- 📜 Follow the
RESTful API
design specification & interface-based programming specification - 🏠 More concise project structure, modular design, improve code readability and maintainability
- 🧰 Based on the
GIN
framework, it provides rich middleware support (JWTAuth, CORS, RequestLogger, RequestRateLimiter, TraceID, Casbin, Recover, GZIP, StaticWebsite) - 🔐 RBAC access control model based on
Casbin
- 🗃️ Database access layer based on
GORM 2.0
- 🔌 Dependency injection based on
WIRE
-- the role of dependency injection itself is to solve the cumbersome initialization process of hierarchical dependencies between modules - ⚡ Log output based on
Zap & Context
, and unified output of key fields such as TraceID/UserID through combination with Context (also supports log hooks written toGORM
) - 🔑 User authentication based on
JWT
- 🔬 Automatically generate
Swagger
documentation based onSwaggo
- Preview - 🧪 Implement API unit testing based on
testify
- 💯 Stateless service, horizontally scalable, improves service availability - dynamic permission management of Casbin is implemented through scheduled tasks and Redis
- 🔨 Complete efficiency tools, can develop complete code modules through configuration - gin-admin-cli
- Frontend project based on Ant Design React - Preview: admin/abc-123
- Frontend project based on Vue.js - Preview: admin/abc-123
- Go 1.19+
- Wire
go install github.com/google/wire/cmd/wire@latest
- Swag
go install github.com/swaggo/swag/cmd/swag@latest
- GIN-ADMIN-CLI
go install github.com/gin-admin/gin-admin-cli/v10@latest
gin-admin-cli new -d ~/go/src --name testapp --desc 'A test API service based on golang.' --pkg 'github.com/xxx/testapp'
cd ~/go/src/testapp
make start
# or
go run main.go start
For more detailed usage instructions, please refer to gin-admin-cli
gin-admin-cli gen -d . -m CMS --structs Article --structs-comment 'Article management'
gin-admin-cli rm -d . -m CMS --structs Article
make build
# or
go build -ldflags "-w -s -X main.VERSION=v1.0.0" -o ginadmin
make swagger
# or
swag init --parseDependency --generalInfo ./main.go --output ./internal/swagger
make wire
# or
wire gen ./internal/wirex
├── cmd
│ ├── start.go
│ ├── stop.go
│ └── version.go
├── configs
│ ├── dev
│ │ ├── logging.toml (Log configuration file)
│ │ ├── middleware.toml (Middleware configuration file)
│ │ └── server.toml (Service configuration file)
│ ├── menu.json (Initialize menu file)
│ └── rbac_model.conf (Casbin RBAC model configuration file)
├── internal
│ ├── bootstrap
│ │ ├── bootstrap.go (Initialization)
│ │ ├── http.go (HTTP service)
│ │ └── logger.go (Log service)
│ ├── config (Configuration file)
│ │ ├── config.go
│ │ ├── consts.go
│ │ ├── middleware.go
│ │ └── parse.go
│ ├── mods
│ │ ├── rbac (RBAC module)
│ │ │ ├── api (API layer)
│ │ │ ├── biz (Business logic layer)
│ │ │ ├── dal (Data access layer)
│ │ │ ├── schema (Data model layer)
│ │ │ ├── casbin.go (Casbin initialization)
│ │ │ ├── main.go (Module initialization)
│ │ │ └── wire.go (Dependency injection)
│ │ ├── sys
│ │ │ ├── api
│ │ │ ├── biz
│ │ │ ├── dal
│ │ │ ├── schema
│ │ │ ├── main.go
│ │ │ └── wire.go
│ │ └── mods.go
│ ├── utility
│ │ └── prom
│ │ └── prom.go (Prometheus)
│ └── wirex (Dependency injection)
│ ├── injector.go
│ ├── wire.go
│ └── wire_gen.go
├── test (Unit test)
│ ├── menu_test.go
│ ├── role_test.go
│ ├── test.go
│ └── user_test.go
├── Dockerfile
├── Makefile
├── README.md
├── go.mod
├── go.sum
└── main.go (Entry)