gin-admin

command module
v10.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 18, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

README ΒΆ

Gin-Admin

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

English | δΈ­ζ–‡

LICENSE Language Go Report Card GitHub release GitHub release date GoDoc

Features

  • πŸ“œ 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 to GORM)
  • πŸ”‘ User authentication based on JWT
  • πŸ”¬ Automatically generate Swagger documentation based on Swaggo - 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

swagger

Frontend

Dependencies

  • 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

Quick Start

Create a new project
gin-admin-cli new -d ~/go/src --name testapp --desc 'A test API service based on golang.' --pkg 'github.com/xxx/testapp'
Start the service
cd ~/go/src/testapp
make start
# or
go run main.go start
Generate a new module

For more detailed usage instructions, please refer to gin-admin-cli

gin-admin-cli gen -d . -m CMS -s Article --structs-comment 'Article management'
Remove a module
gin-admin-cli rm -d . -m CMS -s Article
Build the service
make build
# or
go build -ldflags "-w -s -X main.VERSION=v1.0.0" -o ginadmin
Generate swagger docs
make swagger
# or
swag init --parseDependency --generalInfo ./main.go --output ./internal/swagger
Generate wire inject
make wire
# or
wire gen ./internal/wirex

Project Layout

β”œβ”€β”€ 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)

Community

Documentation ΒΆ

The Go Gopher

There is no documentation for this package.

Directories ΒΆ

Path Synopsis
internal
swagger
Code generated by swaggo/swag.
Code generated by swaggo/swag.
pkg
errors
Package errors provides a way to return detailed information for an request error.
Package errors provides a way to return detailed information for an request error.
oss

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL