|
1 | 1 | # [Gin](https://github.com/gin-gonic/gin)-Admin
|
2 | 2 |
|
3 | 3 | > A lightweight, flexible, elegant and full-featured RBAC scaffolding based on GIN + GORM 2.0 + Casbin 2.0 + Wire DI.
|
| 4 | +
|
| 5 | +English | [中文](README_CN.md) |
| 6 | + |
| 7 | +[![ReportCard][reportcard-image]][reportcard-url] [![GoDoc][godoc-image]][godoc-url] [![License][license-image]][license-url] |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- :scroll: Follow the `RESTful API` design specification & interface-based programming specification |
| 12 | +- :house: More concise project structure, modular design, improve code readability and maintainability |
| 13 | +- :toolbox: Based on the `GIN` framework, it provides rich middleware support (JWTAuth, CORS, RequestLogger, RequestRateLimiter, TraceID, Casbin, Recover, GZIP, StaticWebsite) |
| 14 | +- :closed_lock_with_key: RBAC access control model based on `Casbin` |
| 15 | +- :card_file_box: Database access layer based on `GORM 2.0` |
| 16 | +- :electric_plug: Dependency injection based on `WIRE` -- the role of dependency injection itself is to solve the cumbersome initialization process of hierarchical dependencies between modules |
| 17 | +- :zap: 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 to `GORM`) |
| 18 | +- :key: User authentication based on `JWT` |
| 19 | +- :microscope: Automatically generate `Swagger` documentation based on `Swaggo` - [Preview](http://101.42.232.163:8040/swagger/index.html) |
| 20 | +- :test_tube: Implement API unit testing based on `testify` |
| 21 | +- :100: Stateless service, horizontally scalable, improves service availability - dynamic permission management of Casbin is implemented through scheduled tasks and Redis |
| 22 | +- :hammer: Complete efficiency tools, can develop complete code modules through configuration - [gin-admin-cli](https://github.com/gin-admin/gin-admin-cli) |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +## Frontend |
| 27 | + |
| 28 | +- [Frontend project based on Ant Design React](https://github.com/gin-admin/gin-admin-frontend) - [Preview](http://101.42.232.163:8040/): admin/abc-123 |
| 29 | +- [Frontend project based on Vue.js](https://github.com/gin-admin/gin-admin-vue) - [Preview](http://101.42.232.163:8080/): admin/abc-123 |
| 30 | + |
| 31 | +## Dependencies |
| 32 | + |
| 33 | +- [Go](https://golang.org/) 1.19+ |
| 34 | +- [Wire](github.com/google/wire) `go install github.com/google/wire/cmd/wire@latest` |
| 35 | +- [Swag](github.com/swaggo/swag) `go install github.com/swaggo/swag/cmd/swag@latest` |
| 36 | +- [GIN-ADMIN-CLI](https://github.com/gin-admin/gin-admin-cli) `go install github.com/gin-admin/gin-admin-cli/v10@latest` |
| 37 | + |
| 38 | +## Quick Start |
| 39 | + |
| 40 | +### Create a new project |
| 41 | + |
| 42 | +```bash |
| 43 | +gin-admin-cli new -d ~/go/src --name testapp --desc 'A test API service based on golang.' --pkg 'github.com/xxx/testapp' |
| 44 | +``` |
| 45 | + |
| 46 | +### Start the service |
| 47 | + |
| 48 | +```bash |
| 49 | +cd ~/go/src/testapp |
| 50 | +make start |
| 51 | +# or |
| 52 | +go run main.go start |
| 53 | +``` |
| 54 | + |
| 55 | +### Generate a new module |
| 56 | + |
| 57 | +> For more detailed usage instructions, please refer to [gin-admin-cli](https://github.com/gin-admin/gin-admin-cli) |
| 58 | +
|
| 59 | +```bash |
| 60 | +gin-admin-cli gen -d . -m CMS -s Article --structs-comment 'Article management' |
| 61 | +``` |
| 62 | + |
| 63 | +### Remove a module |
| 64 | + |
| 65 | +```bash |
| 66 | +gin-admin-cli rm -d . -m CMS -s Article |
| 67 | +``` |
| 68 | + |
| 69 | +### Build the service |
| 70 | + |
| 71 | +```bash |
| 72 | +make build |
| 73 | +# or |
| 74 | +go build -ldflags "-w -s -X main.VERSION=v1.0.0" -o ginadmin |
| 75 | +``` |
| 76 | + |
| 77 | +### Generate swagger docs |
| 78 | + |
| 79 | +```bash |
| 80 | +make swagger |
| 81 | +# or |
| 82 | +swag init --parseDependency --generalInfo ./main.go --output ./internal/swagger |
| 83 | +``` |
| 84 | + |
| 85 | +### Generate wire inject |
| 86 | + |
| 87 | +```bash |
| 88 | +make wire |
| 89 | +# or |
| 90 | +wire gen ./internal/wirex |
| 91 | +``` |
| 92 | + |
| 93 | +## Project Layout |
| 94 | + |
| 95 | +```text |
| 96 | +├── cmd |
| 97 | +│ ├── start.go |
| 98 | +│ ├── stop.go |
| 99 | +│ └── version.go |
| 100 | +├── configs |
| 101 | +│ ├── dev |
| 102 | +│ │ ├── logging.toml |
| 103 | +│ │ ├── middleware.toml |
| 104 | +│ │ └── server.toml |
| 105 | +│ ├── menu.json |
| 106 | +│ └── rbac_model.conf |
| 107 | +├── internal |
| 108 | +│ ├── bootstrap |
| 109 | +│ │ ├── bootstrap.go |
| 110 | +│ │ ├── http.go |
| 111 | +│ │ └── logger.go |
| 112 | +│ ├── config |
| 113 | +│ │ ├── config.go |
| 114 | +│ │ ├── consts.go |
| 115 | +│ │ ├── middleware.go |
| 116 | +│ │ └── parse.go |
| 117 | +│ ├── mods |
| 118 | +│ │ ├── rbac |
| 119 | +│ │ │ ├── api |
| 120 | +│ │ │ ├── biz |
| 121 | +│ │ │ ├── dal |
| 122 | +│ │ │ ├── schema |
| 123 | +│ │ │ ├── casbin.go |
| 124 | +│ │ │ ├── main.go |
| 125 | +│ │ │ └── wire.go |
| 126 | +│ │ ├── sys |
| 127 | +│ │ │ ├── api |
| 128 | +│ │ │ ├── biz |
| 129 | +│ │ │ ├── dal |
| 130 | +│ │ │ ├── schema |
| 131 | +│ │ │ ├── main.go |
| 132 | +│ │ │ └── wire.go |
| 133 | +│ │ └── mods.go |
| 134 | +│ ├── utility |
| 135 | +│ │ └── prom |
| 136 | +│ │ └── prom.go |
| 137 | +│ └── wirex |
| 138 | +│ ├── injector.go |
| 139 | +│ ├── wire.go |
| 140 | +│ └── wire_gen.go |
| 141 | +├── test |
| 142 | +│ ├── menu_test.go |
| 143 | +│ ├── role_test.go |
| 144 | +│ ├── test.go |
| 145 | +│ └── user_test.go |
| 146 | +├── Dockerfile |
| 147 | +├── Makefile |
| 148 | +├── README.md |
| 149 | +├── go.mod |
| 150 | +├── go.sum |
| 151 | +└── main.go |
| 152 | +``` |
| 153 | + |
| 154 | +## Community |
| 155 | + |
| 156 | +- [Discord](https://discord.gg/UCnpActY) |
| 157 | + |
| 158 | +## MIT License |
| 159 | + |
| 160 | +```text |
| 161 | +Copyright (c) 2023 Lyric |
| 162 | +``` |
| 163 | + |
| 164 | +[reportcard-url]: https://goreportcard.com/report/github.com/LyricTian/gin-admin |
| 165 | +[reportcard-image]: https://goreportcard.com/badge/github.com/LyricTian/gin-admin |
| 166 | +[godoc-url]: https://pkg.go.dev/github.com/LyricTian/gin-admin/v10 |
| 167 | +[godoc-image]: https://godoc.org/github.com/LyricTian/gin-admin?status.svg |
| 168 | +[license-url]: http://opensource.org/licenses/MIT |
| 169 | +[license-image]: https://img.shields.io/npm/l/express.svg |
0 commit comments