go-admin Authority Management System

repository·master·Indexed 11 days ago

https://github.com/go-admin-team/go-admin

A full-stack authority management system for rapid development featuring a Gin-based backend and a Vue frontend (Element UI or Arco Design). It includes built-in RBAC via Casbin, JWT authentication, GORM database support, Swagger documentation, and tools for code generation and form building.

Tokens
15.6K
Snippets
45
Records
52
Agent score
95%

What's inside go-admin

  1. Overview of go-admin features

    master

    go-admin is a decoupled (frontend/backend) permission management system built with Gin (backend) and Vue/Element UI/Arco Design/Ant Design (frontend).

    Key features include:

    • RESTful API design.
    • RBAC access control using Casbin.
    • JWT authentication.
    • Swagger documentation (via swaggo).
    • GORM based database storage (supports multiple database types).
    • Multi-tenancy support (database-per-tenant model).
    • Code Generation and Form Building tools for rapid development.
    • Multi-command CLI interface for migrations and server management.
  2. Overview of go-admin

    master

    go-admin is a front-end and back-end separated authority management system. It uses Gin for the backend API and Vue with either Element UI or Arco Design for the frontend.

    Key features include:

    • RESTful API design.
    • RBAC access control via Casbin.
    • JWT authentication.
    • Swagger documentation (via swaggo).
    • GORM based database storage (supports multiple database types).
    • Code generation and Form builder tools to accelerate development.
    • Multi-command mode for service management (e.g., migration, server startup).
  3. Clone the go-admin repositories

    master

    Create a development directory and clone both the backend and frontend repositories into it:

    # Create a development directory
    mkdir goadmin
    cd goadmin
    
    # Get backend code
    git clone https://github.com/go-admin-team/go-admin.git
    
    # Get the front-end code
    git clone https://github.com/go-admin-team/go-admin-ui.git
  4. Start the UI interactive terminal

    master

    To run the frontend development server, use pnpm:

    1. Install pnpm (if not already installed):

      npm install -g pnpm
    2. Install dependencies and run:

      pnpm install
      pnpm dev
    # Install pnpm if you don't have it
    npm install -g pnpm
    
    # Installation dependencies
    pnpm install
    
    # Start service
    pnpm dev
  5. Run go-admin using Docker

    master

    You can compile and run the backend using Docker.

    1. Build the image:

      docker build -t go-admin .
    2. Run the container: Map the local configuration file to the container and expose port 8000.

      docker run --name go-admin -p 8000:8000 -v /config/settings.yml:/config/settings.yml -d go-admin-server
    # Compile the image
    docker build -t go-admin .
    
    # Start the container
    docker run --name go-admin -p 8000:8000 -v /config/settings.yml:/config/settings.yml -d go-admin-server
  6. Build and deploy with Docker

    master

    You can build a Docker image and run the service using the following commands:

    # Build the image
    docker build -t go-admin .
    
    # Run the container
    # Maps port 8000 and mounts the local config file
    docker run --name go-admin -p 8000:8000 -v /config/settings.yml:/config/settings.yml -d go-admin-server
    # Build image
    docker build -t go-admin .
    
    # Run container
    docker run --name go-admin -p 8000:8000 -v /config/settings.yml:/config/settings.yml -d go-admin-server
  7. Cross-compile the backend

    master

    To compile the Go backend for different operating systems, use the GOOS and GOARCH environment variables:

    For Windows:

    env GOOS=windows GOARCH=amd64 go build main.go

    For Linux:

    env GOOS=linux GOARCH=amd64 go build main.go
    # windows
    env GOOS=windows GOARCH=amd64 go build main.go
    
    # linux
    env GOOS=linux GOARCH=amd64 go build main.go
  8. Run the go-admin backend service

    master

    Follow these steps to build and run the backend:

    1. Prepare dependencies:

      cd ./go-admin
      go mod tidy
      go build
    2. Configure database: Edit go-admin/config/settings.yml. Update the settings.database section with your database credentials and verify the log path.

    3. Initialize database (First time only): Use the migrate command to set up the database schema and initial data.

      • macOS/Linux: ./go-admin migrate -c config/settings.dev.yml
      • Windows: go-admin.exe migrate -c config/settings.dev.yml
    4. Start the server:

      • macOS/Linux: ./go-admin server -c config/settings.yml
      • Windows: go-admin.exe server -c config/settings.yml

    Tip: To automatically add missing interface data to the sys_api table on startup, use the -a true flag:

    ./go-admin server -c config/settings.yml -a true
    # 1. Prepare dependencies
    cd ./go-admin
    go mod tidy
    go build
    
    # 2. Initialize database (macOS/Linux)
    ./go-admin migrate -c config/settings.dev.yml
    
    # 3. Start server with auto-api-sync
    ./go-admin server -c config/settings.yml -a true
  9. Initialize the database and start the backend server

    master

    The backend uses a multi-command mode. You must first migrate the database before starting the server.

    1. Database Migration

    Run the migration command to initialize database resource information.

    macOS/Linux:

    ./go-admin migrate -c config/settings.dev.yml

    Windows:

    go-admin.exe migrate -c config/settings.dev.yml

    2. Start the Server

    Once migrated, start the API service.

    macOS/Linux:

    ./go-admin server -c config/settings.yml

    Windows:

    go-admin.exe server -c config/settings.yml
    # Use under macOS or linux
    $ ./go-admin migrate -c config/settings.dev.yml
    
    # Use under windows
    $ go-admin.exe migrate -c config/settings.dev.yml
    
    # Start the project (macOS/Linux)
    $ ./go-admin server -c config/settings.yml
    
    # Start the project (Windows)
    $ go-admin.exe server -c config/settings.yml
  10. Run the go-admin UI (Frontend)

    master

    Navigate to the go-admin-ui directory and use pnpm to start the development server:

    cd go-admin-ui
    
    # Install dependencies (use mirror if in China)
    pnpm install --registry=https://registry.npmmirror.com
    
    # Start development server
    pnpm dev
    cd go-admin-ui
    pnpm install
    pnpm dev
  11. Build and configure the go-admin backend

    master

    Follow these steps to compile and configure the backend service:

    1. Update dependencies and build:

      cd ./go-admin
      go mod tidy
      go build
    2. Configure database and logs: Edit the configuration file located at go-admin/config/settings.yml.

      • Update the settings.database section with your database credentials.
      • Verify the log file paths.

    Note for Windows users: If you encounter cgo errors (e.g., exec: "gcc": executable file not found), you must install a C compiler (like MinGW) to support go-sqlite3.

    # Enter the go-admin backend project
    cd ./go-admin
    
    # Update dependencies
    go mod tidy
    
    # Compile the project
    go build
    
    # Change setting 
    # File path go-admin/config/settings.yml
    vi ./config/settings.yml
  12. Install and clone go-admin repositories

    master

    Create a development directory and clone both the backend and frontend repositories into it:

    # Create development directory
    mkdir goadmin
    cd goadmin
    
    # Get backend code
    git clone https://github.com/go-admin-team/go-admin.git
    
    # Get frontend code
    git clone https://github.com/go-admin-team/go-admin-ui.git