Giter VIP home page Giter VIP logo

gin-admin's Introduction

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 --structs Article --structs-comment 'Article management'

Remove a module

gin-admin-cli rm -d . -m CMS --structs 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

gin-admin's People

Contributors

chenyu1990 avatar conight avatar crazyrunsnail avatar ezewu avatar fan-tastic-z avatar gopkg-dev avatar linzhengen avatar longlycode avatar lostmaniac avatar luky-jing avatar lvisei avatar lyrictian avatar peanut-cc avatar pingtest avatar yz271544 avatar zbml avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.