taskadmin

package module
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

taskadmin

Standalone admin interface for taskstore, following the folder-per-controller pattern used by shopadmin.

Extracted from github.com/dracory/taskstore/admin.

Structure

  • taskadmin.go — AdminOptions, New(), Handle() dispatcher
  • shared/ — UiConfig/UiBase, FuncLayout + default layout, breadcrumbs, page header, section nav, URL/query helpers
  • home/ — dashboard landing page
  • task_queue_manager/ — queued task manager. Vue page (tasks.html + tasks.js) plus JSON AJAX handlers (handle_*_ajax.go) for loading, enqueueing, restarting, requeueing, deleting, and editing task parameters
  • task_definition_manager/ — task definition manager. Vue page (definitions.html + definitions.js) plus JSON AJAX handlers for loading, creating, updating, and deleting definitions
  • testutils/ — in-memory SQLite store for tests

Each manager is a thin ?action= dispatcher: with no action it renders the page (layout + embedded Vue assets); with an action it returns a JSON response via github.com/dracory/api.

Usage

admin, err := taskadmin.New(taskadmin.AdminOptions{
    Store:  store,           // taskstore.StoreInterface (required)
    Logger: slog.Default(),  // required

    // optional
    FuncLayout: func(w http.ResponseWriter, r *http.Request,
        webpageTitle, webpageHtml string, options shared.LayoutOptions) string {
        return myAdminLayout(w, r, webpageTitle, webpageHtml, options)
    },
    AdminHomeURL: "/admin",      // default
    TaskAdminURL: "/admin/task", // default
    AuthUserID: func(r *http.Request) string {
        return authUserID(r) // "" => redirect to AdminHomeURL
    },
})
if err != nil {
    panic(err)
}

mux.HandleFunc("/admin/task", admin.Handle)

Routing is by ?controller= query parameter (home, task-queue-manager, task-definition-manager), defaulting to home.

Testing

go test ./...
# or
task test

Documentation

Overview

Package taskadmin provides a standalone task admin interface following the folder-per-controller pattern. Each controller is in its own subfolder and handles its own views and AJAX data.

This module is modeled on github.com/dracory/shopadmin and was extracted from github.com/dracory/taskstore/admin.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStoreRequired  = errors.New("store is required")
	ErrLoggerRequired = errors.New("logger is required")
)

Functions

This section is empty.

Types

type AdminInterface

type AdminInterface interface {
	Handle(w http.ResponseWriter, r *http.Request)
}

AdminInterface defines the interface for the task admin

func New

func New(opts AdminOptions) (AdminInterface, error)

New creates a new task admin instance. Returns ErrStoreRequired if Store is nil, ErrLoggerRequired if Logger is nil.

type AdminOptions

type AdminOptions struct {
	// Store is the taskstore.StoreInterface (required)
	Store taskstore.StoreInterface

	// Logger is required
	Logger *slog.Logger

	// FuncLayout is an optional function to render the admin interface
	// inside your own layout (branding, menus, etc.). It receives the
	// request and response writer so the host project can access request
	// context (auth user, locale, etc.) when rendering the layout.
	// If nil, a default bare-bones HTML page is used (Bootstrap CDN).
	FuncLayout shared.FuncLayout

	// AdminHomeURL is the URL for the admin home page (default: "/admin")
	AdminHomeURL string

	// TaskAdminURL is the base URL for the task admin (default: "/admin/task")
	TaskAdminURL string

	// AuthUserID returns the authenticated user ID from the request.
	// If it returns "", the user is treated as unauthenticated.
	// Optional — nil disables the auth check.
	AuthUserID func(r *http.Request) string
}

AdminOptions contains all dependencies and configuration for the task admin.

Directories

Path Synopsis
Package testutils provides shared test helpers for taskadmin: an in-memory SQLite task store and a mock Layout implementation.
Package testutils provides shared test helpers for taskadmin: an in-memory SQLite task store and a mock Layout implementation.

Jump to

Keyboard shortcuts

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