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)