GoAdmin

repository·main·Indexed 27 days ago

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

A toolkit for building data visualization admin panels for Golang applications. GoAdmin provides features such as RBAC, multiple UI themes, and a plugin system to help developers rapidly deploy admin interfaces. It includes a CLI tool called `adm` for project bootstrapping and supports various architectures, including pure Golang, frontend templates, and Vue.js integrations.

Tokens
2.5K
Snippets
5
Records
12
Agent score
94%

What's inside go-admin

  1. Overview of GoAdmin features

    main

    GoAdmin is a framework for building data visualization and management platforms in Golang. Key features include:

    • High Productivity: Build a functional admin backend in under 10 minutes.
    • Theming: Default theme is adminlte, with more themes in development.
    • Plugin System: Extensible architecture via plugins.
    • Authentication: Out-of-the-box RBAC (Role-Based Access Control) system.
    • Framework Support: Compatible with most major Go frameworks for easy integration and extension.
  2. Quickstart with GoAdmin CLI

    main

    You can quickly bootstrap a new GoAdmin project using the adm command-line tool. Follow these steps to initialize a web-based project:

    1. Create and enter a new project directory.
    2. Install the adm tool using go install.
    3. Initialize the project with the web template.

    This process sets up the basic structure required to start building your admin panel.

    $ mkdir new_project && cd new_project
    $ go install github.com/GoAdminGroup/adm@latest
    $ adm init web
  3. Manage dependencies using Go modules

    main

    GoAdmin uses Go modules for dependency management. This requires Go version > 1.11 and git to be installed.

    To add or update dependencies, use go get. After modifying dependencies, you must tidy the module files and vendor them to ensure the go.mod, go.sum, and vendor directory are consistent before committing.

    # Pick the latest tagged release.
    go get example.com/some/module/pkg
    
    # Pick a specific version.
    go get example.com/some/module/pkg@vX.Y.Z
    
    # Clean up and vendor dependencies
    go mod tidy
    go mod vendor
    git add go.mod go.sum vendor
    git commit
  4. Set up a local development environment for GoAdmin

    main

    To contribute to GoAdmin, fork the master branch and clone it into your $GOPATH/src/github.com/GoAdminGroup/go-admin directory.

    Note: Running go get github.com/GoAdminGroup/go-admin may return a warning stating no Go files in ..., which is expected behavior.

    Before submitting any code, you must run the test suite using the provided Makefile.

  5. Deploy go-admin using Docker Compose

    main

    You can deploy the goadmin service along with database backends (MySQL or PostgreSQL) and Portainer using the provided docker-compose.yml.

    By default, the setup includes:

    • goadmin: Runs the josingcjx/goadmin:1.1 image. It mounts the current directory to /home/goadmin inside the container and starts with /bin/bash.
    • mysql: Runs mysql:5.6 with the root password set to goadmin.
    • postgres: Runs postgres:latest with the password set to goadmin.
    • portainer: Runs portainer/portainer:latest for container management, accessible on port 9000.
    version: "3.3"
    services:
      mysql:
        image: mysql:5.6
        container_name: mysql
        ports:
          - "3306:3306"
        volumes:
          - mysql:/data
        networks:
          - goadmin
        environment:
          - MYSQL_ROOT_PASSWORD=goadmin
      postgres:
        image: postgres:latest
        container_name: postgres
        ports:
          - "5432:5432"
        volumes:
          - postgres:/data
        networks:
          - goadmin
        environment:
          - POSTGRES_PASSWORD=goadmin
      goadmin:
        image: josingcjx/goadmin:1.1
        tty: true
        container_name: goadmin
        volumes:
          - .:/home/goadmin
        networks:
          - goadmin
        command:
          - /bin/bash
      portainer:
        image: portainer/portainer:latest
        container_name: portainer
        restart: always
        ports:
          - "9000:9000"
        networks:
          - goadmin
        volumes:
          - /var/run/docker.sock:/var/run/docker.sock
          - portainer:/data
    networks:
      goadmin: {}
    volumes:
      portainer: {}
      postgres: {}
      mysql: {}
  6. Explore GoAdmin implementation examples

    main

    GoAdmin provides several example repositories depending on your preferred architecture and frontend stack:

    • Pure Golang: A simple implementation with minimal dependencies.
    • Golang with Frontend Template: Allows you to customize the frontend templates yourself.
    • Golang with Vue: Designed for developers with Vue.js experience.

    Refer to these examples to understand how to integrate GoAdmin into your specific application structure.

  7. Configure Ethereal frontend scroll settings

    main

    The main.js asset (part of the Ethereal template by HTML5 UP) uses a settings object to control various interaction behaviors. Note that in the current version, scrollWheel.enabled is explicitly set to false in the source code to prevent broken scrolling behavior.

    Available configuration categories:

    • keyboardShortcuts: Controls scrolling via arrow keys and Page Up/Down.
      • enabled (boolean)
      • distance (number): Pixels to scroll per keypress.
    • scrollWheel: Controls mouse wheel interaction.
      • enabled (boolean): Currently hardcoded to false in the source.
      • factor (number): Scroll speed multiplier.
    • scrollZones: Enables scrolling by hovering over the left/right edges of the screen.
      • enabled (boolean)
      • speed (number): Scrolling speed.
    • dragging: Enables mouse dragging to scroll the main wrapper.
      • enabled (boolean)
      • momentum (number): Momentum factor (0 to 1).
      • threshold (number): Drag threshold in pixels.
    • excludeSelector: A CSS selector (default: 'input:focus, select:focus, textarea:focus, audio, video, iframe') used to prevent keyboard/mouse events from bubbling when interacting with these elements.
    • linkScrollSpeed: Duration in milliseconds for anchor link animations.
  8. Configure go-admin Docker environment variables and ports

    main

    When using the Docker Compose setup, the following service configurations are exposed:

    goadmin service

    • Image: josingcjx/goadmin:1.1
    • Volume Mount: The local directory . is mounted to /home/goadmin inside the container.
    • Command: Defaults to /bin/bash.

    Database services

    • MySQL:
      • Port: 3306:3306
      • Environment Variable: MYSQL_ROOT_PASSWORD (default: goadmin)
    • PostgreSQL:
      • Port: 5432:5432
      • Environment Variable: POSTGRES_PASSWORD (default: goadmin)

    Portainer service

    • Port: 9000:9000
    • Volume Mounts:
      • /var/run/docker.sock:/var/run/docker.sock (required for Docker management)
      • portainer:/data
  9. Use the Gallery modal feature

    main

    The template includes a built-in gallery system. When an element with the class .gallery contains an anchor <a> tag pointing to an image file (ending in .jpg, .gif, .png, or .mp4), clicking the link will open the image in a modal.

    Behavior:

    • Clicking an image link opens a modal and sets the image src to the link's href.
    • Clicking inside the .modal or pressing the Escape key closes the modal.
    • The modal includes a loading state (.loaded class) and handles focus management.
  10. Implement a custom plugin using plugins.Base

    main

    To create a custom plugin in go-admin, define a struct that embeds *plugins.Base. You must export a variable (conventionally named Plugin) that initializes your struct with a plugins.Base instance containing a unique PlugName.

    Implement the InitPlugin(srv service.List) method to handle plugin initialization. Inside this method, call example.InitBase(srv, "plugname") to set up the base plugin functionality and use the provided service.List to access system services.

    type Example struct {
    	*plugins.Base
    }
    
    var Plugin = &Example{
    	Base: &plugins.Base{PlugName: "example"},
    }
    
    func (example *Example) InitPlugin(srv service.List) {
    	example.InitBase(srv, "example")
    	// Perform further initialization here
    }
  11. Register routes within a custom plugin

    main

    Custom plugins can define their own routing logic by creating a *context.App instance. Within your plugin's initialization flow, use context.NewApp() to create a new application instance, then use app.Group(prefix) to define route groups.

    Routes can be protected using auth.Middleware and can access database connections via db.GetConnection(srv). The resulting *context.App should be assigned to the Plugin.App field so the core system can utilize it.

    func (example *Example) initRouter(prefix string, srv service.List) *context.App {
    	app := context.NewApp()
    	route := app.Group(prefix)
    	route.GET("/example", auth.Middleware(db.GetConnection(srv)), example.TestHandler)
    	return app
    }
    
    // In InitPlugin:
    // Plugin.App = example.initRouter(c.Prefix(), srv)