admin

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2026 License: MIT Imports: 19 Imported by: 0

README

Go Admin

A high-performance, modern, and extensible administration framework for Go, inspired by Active Admin.

Go Admin uses reflection and GORM to automatically generate a professional-grade back-office for your database models with minimal configuration.

Features

  • 🔐 Secure Authentication: Session-based login with bcrypt password hashing.
  • 📂 Resource Grouping: Organize your models into logical categories.
  • 📊 Visual Dashboard: Customizable charts (powered by Chart.js) and stat widgets.
  • 🔍 Powerful Filtering: Predefined scopes (tabs) and dynamic search filters.
  • ⛓️ Associations: Automatic handling of HasMany and BelongsTo relationships.
  • 📝 Audit Logging: Full history of every Create, Update, and Delete action.
  • 📦 Batch Actions: Perform operations on multiple records at once.
  • 📥 CSV Export: Export filtered data directly to CSV.
  • 🎨 Decorators: Customize how fields are rendered (Currency, Badges, etc.).
  • 🚀 Portable: Everything (HTML/CSS/JS) is bundled into your binary using go:embed.

Installation

go get github.com/go-packs/go-admin

Quick Start

package main

import (
    "github.com/go-packs/go-admin" // Single user-friendly import
    "gorm.io/driver/sqlite"
    "gorm.io/gorm"
    "net/http"
)

type Product struct {
    ID    uint   `gorm:"primaryKey"`
    Name  string
    Price float64
}

func main() {
    db, _ := gorm.Open(sqlite.Open("admin.db"), &gorm.Config{})
    db.AutoMigrate(&Product{}, &admin.AdminUser{}, &admin.Permission{}, &admin.Session{}, &admin.AuditLog{})

    // Initialize Admin
    adm := admin.NewRegistry(db)

    // Register a Resource
    adm.Register(Product{}).
        SetGroup("Inventory").
        RegisterField("ID", "ID", true).
        RegisterField("Name", "Product Name", false).
        RegisterField("Price", "Price", false)

    // Start Server
    http.Handle("/admin/", adm)
    http.ListenAndServe(":8080", nil)
}

Documentation

For full feature documentation including Associations, Scopes, Custom Actions, and Charts, please refer to the Usage Guide.

License

This project is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultConfig

func DefaultConfig() *config.Config

Public Factory Functions

func LoadConfig

func LoadConfig(path string) (*config.Config, error)

func NewResource

func NewResource(model interface{}) *resource.Resource

Types

type AdminUser

type AdminUser = models.AdminUser

type AssociationData

type AssociationData struct {
	Resource *resource.Resource
	Fields   []resource.Field
	Items    []map[string]interface{}
	Options  []map[string]interface{}
}

type AuditLog

type AuditLog = models.AuditLog

type Chart

type Chart struct {
	Label string
	Type  string
	Data  func(db *gorm.DB) (labels []string, values []float64)
}

type ChartWidget

type ChartWidget struct {
	ID, Label, Type string
	Labels          []string
	Values          []float64
}

type Config

type Config = config.Config

type Field

type Field = resource.Field

type Page

type Page struct {
	Name, Group string
	Handler     http.HandlerFunc
}

type PageData

type PageData struct {
	SiteTitle          string
	Resources          map[string]*resource.Resource
	GroupedResources   map[string][]*resource.Resource
	GroupedPages       map[string][]*Page
	CurrentResource    *resource.Resource
	Fields             []resource.Field
	Data               []map[string]interface{}
	Item               map[string]interface{}
	Filters            map[string]string
	User               *models.AdminUser
	Stats              []Stat
	Error              string
	Flash              string
	CSS                template.CSS
	Page, PerPage      int
	TotalPages         int
	TotalCount         int64
	HasPrev, HasNext   bool
	PrevPage, NextPage int
	Scopes             []resource.Scope
	CurrentScope       string
	Associations       map[string]AssociationData
	ChartData          []ChartWidget
	SortField          string
	SortOrder          string
	RenderedSidebars   map[string]template.HTML
}

type Permission

type Permission = models.Permission

type Registry

type Registry struct {
	DB        *gorm.DB
	Resources map[string]*resource.Resource
	Pages     map[string]*Page
	Charts    []Chart
	Config    *config.Config
}

func NewRegistry

func NewRegistry(db *gorm.DB) *Registry

func (*Registry) AddChart

func (reg *Registry) AddChart(l, t string, p func(db *gorm.DB) ([]string, []float64))

func (*Registry) AddPage

func (reg *Registry) AddPage(n, g string, h http.HandlerFunc)

func (*Registry) Create

func (reg *Registry) Create(resourceName string, data interface{}) error

func (*Registry) Delete

func (reg *Registry) Delete(resourceName string, id interface{}) error

func (*Registry) Get

func (reg *Registry) Get(resourceName string, id interface{}) (interface{}, error)

func (*Registry) GetResource

func (reg *Registry) GetResource(n string) (*resource.Resource, bool)

func (*Registry) GetUserFromRequest

func (reg *Registry) GetUserFromRequest(r *http.Request) (*models.AdminUser, string)

func (*Registry) IsAllowed

func (reg *Registry) IsAllowed(role, resource, action string) bool

func (*Registry) List

func (reg *Registry) List(resourceName string) (interface{}, error)

func (*Registry) RecordAction

func (reg *Registry) RecordAction(user *models.AdminUser, resName, recordID, action, changes string)

func (*Registry) Register

func (reg *Registry) Register(m interface{}) *resource.Resource

func (*Registry) RenderCustomPage

func (reg *Registry) RenderCustomPage(w http.ResponseWriter, r *http.Request, title string, content template.HTML)

func (*Registry) ResourceNames

func (reg *Registry) ResourceNames() []string

func (*Registry) ServeHTTP

func (reg *Registry) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface and routes requests to sub-handlers.

func (*Registry) SetConfig

func (reg *Registry) SetConfig(c *config.Config)

func (*Registry) Update

func (reg *Registry) Update(resourceName string, data interface{}) error

type Resource

type Resource = resource.Resource

Public Type Aliases

type Scope

type Scope = resource.Scope

type Session

type Session = models.Session

type Stat

type Stat struct {
	Label string
	Value int64
}

Directories

Path Synopsis
cmd
go-admin command

Jump to

Keyboard shortcuts

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