admin

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package admin provides the admin panel coordinator as a burrow contrib app. It handles layout, navigation, dashboard rendering, and acts as the mount point for admin views contributed by apps implementing HasAdmin.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLayout

func DefaultLayout() string

DefaultLayout returns the template name for the built-in admin layout.

func RequestPath added in v0.6.0

func RequestPath(ctx context.Context) string

RequestPath is a deprecated alias for burrow.RequestPath.

func RequestPathFromContext

func RequestPathFromContext(ctx context.Context) string

RequestPathFromContext is a deprecated alias for burrow.RequestPath.

func WithNavGroups

func WithNavGroups(ctx context.Context, groups []NavGroup) context.Context

WithNavGroups stores nav groups in the context.

Example
package main

import (
	"context"
	"fmt"

	"github.com/oliverandrich/burrow"
	"github.com/oliverandrich/burrow/contrib/admin"
)

func main() {
	groups := []admin.NavGroup{
		{AppName: "users", Items: []burrow.NavItem{{Label: "All Users", URL: "/admin/users"}}},
	}
	ctx := admin.WithNavGroups(context.Background(), groups)

	result := admin.NavGroups(ctx)
	fmt.Println(result[0].AppName, result[0].Items[0].Label)
}
Output:
users All Users

func WithRequestPath

func WithRequestPath(ctx context.Context, path string) context.Context

WithRequestPath is a deprecated alias for burrow.WithRequestPath.

Example
package main

import (
	"context"
	"fmt"

	"github.com/oliverandrich/burrow"
	"github.com/oliverandrich/burrow/contrib/admin"
)

func main() {
	ctx := admin.WithRequestPath(context.Background(), "/admin/users/42")

	fmt.Println(burrow.RequestPath(ctx))
}
Output:
/admin/users/42

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App implements the admin coordinator contrib app.

func New

func New(opts ...Option) *App

New creates a new admin app with the given options. By default, the built-in HTML layout and dashboard renderer are used. Use WithLayout() and WithDashboardRenderer() to override.

func (*App) Configure added in v0.10.0

func (a *App) Configure(cfg *burrow.AppConfig, _ *cli.Command) error

func (*App) Dependencies

func (a *App) Dependencies() []string

Dependencies declares contribs the admin app's templates assume are present: staticfiles serves admin.css, htmx powers the boosted nav, mucss provides the css / theme switcher / pagination templates referenced from admin/layout, and messages provides the flash-message template function used at the top of every admin page.

func (*App) Name

func (a *App) Name() string

func (*App) RequestFuncMap added in v0.4.0

func (a *App) RequestFuncMap(ctx context.Context) template.FuncMap

RequestFuncMap returns request-scoped template functions for the admin dashboard.

func (*App) Routes

func (a *App) Routes(r chi.Router)

Routes creates the /admin group with auth middleware and delegates to all HasAdmin apps.

func (*App) StaticFS added in v0.18.0

func (a *App) StaticFS() (string, fs.FS)

StaticFS returns the embedded admin static assets under the "admin" prefix.

func (*App) TemplateFS

func (a *App) TemplateFS() fs.FS

TemplateFS returns the embedded HTML template files.

func (*App) TranslationFS

func (a *App) TranslationFS() fs.FS

TranslationFS returns the embedded translation files (admin UI labels).

type DashboardGroup added in v0.18.0

type DashboardGroup struct {
	AppName string
	Label   string
	Items   []DashboardItem
}

DashboardGroup holds pre-computed dashboard data for template rendering.

func PrepareDashboard added in v0.18.0

func PrepareDashboard(ctx context.Context, groups []NavGroup) []DashboardGroup

PrepareDashboard pre-computes dashboard groups with translated labels, sorted alphabetically by group name, ready for template rendering.

type DashboardItem added in v0.18.0

type DashboardItem struct {
	Label string
	URL   string
	Icon  template.HTML
}

DashboardItem holds pre-computed data for a single dashboard nav link.

type DashboardRenderer

type DashboardRenderer interface {
	DashboardPage(w http.ResponseWriter, r *http.Request) error
}

DashboardRenderer renders the admin dashboard page.

func DefaultDashboardRenderer

func DefaultDashboardRenderer() DashboardRenderer

DefaultDashboardRenderer returns a DashboardRenderer that uses the built-in HTML templates for the admin dashboard page.

type NavGroup struct {
	AppName string
	Items   []burrow.NavItem
}

NavGroup groups navigation items belonging to one admin app. Each HasAdmin app contributes one group to the admin sidebar.

func NavGroups(ctx context.Context) []NavGroup

NavGroups retrieves nav groups from the context.

func NavGroupsFromContext(ctx context.Context) []NavGroup

NavGroupsFromContext is a deprecated alias for NavGroups.

type Option

type Option func(*App)

Option configures the admin app.

func WithDashboardRenderer

func WithDashboardRenderer(r DashboardRenderer) Option

WithDashboardRenderer sets the dashboard page renderer.

func WithLayout

func WithLayout(layout string) Option

WithLayout sets the layout template name for admin pages.

Jump to

Keyboard shortcuts

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