admin

package
v1.27.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package admin provides a self-hosted visitor analytics admin dashboard.

It is a self-contained, reusable library package: consumers inject their own LayoutInterface, a statsstore.StoreInterface, and optional callbacks via admin.New(admin.Options{...}), and get the full dashboard for free.

The package follows the folder-per-controller pattern: each controller lives in its own subfolder and renders via the injected LayoutInterface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler added in v1.25.0

Handler dispatches the request to the matching controller based on the "controller" query parameter. It writes the response directly to the ResponseWriter.

func New

func New(opts Options) (http.Handler, error)

New creates a new admin instance. It validates required fields and returns an http.Handler that dispatches to the appropriate controller based on the "controller" query parameter.

Types

type Options

type Options struct {
	// Store is the statsstore instance used for all visitor queries. Required.
	Store statsstore.StoreInterface

	// Layout renders the full HTML page. Required.
	Layout shared.LayoutInterface

	// HomeURL is the URL for the admin home page (e.g. "/admin").
	HomeURL string

	// WebsiteUrl is the public site URL.
	WebsiteUrl string

	// BaseURL is the base URL for the stats admin (e.g. "/admin/stats").
	// Defaults to "/admin/stats" when empty.
	BaseURL string

	// CountryNameByIso2 maps an ISO2 code to a human-readable country name.
	// Optional; when nil, raw ISO2 codes are displayed.
	CountryNameByIso2 func(iso2Code string) (string, error)

	// AuthUserID returns the authenticated user ID from the request, or ""
	// when unauthenticated. When nil, auth checks are skipped.
	AuthUserID func(r *http.Request) string

	// FlashError renders a flash error message and returns the redirect
	// response body. When nil, controllers fall back to http.Redirect.
	FlashError func(w http.ResponseWriter, r *http.Request, message string, redirectURL string, delaySeconds int) string

	// Logger is used for internal logging. Defaults to slog.Default().
	Logger *slog.Logger
}

Options contains all dependencies and configuration for the admin dashboard. It extends the original statsstore admin Options with optional callbacks for auth, flash messages, and base URL configuration so the package remains self-contained and reusable by any project.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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