admin

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package admin is a platform module: the admin panel of the project, running inside the same binary as the application.

It brings the parts every project needs anyway — sign in, roles, audit log, business settings pages — and an extension point for the project's own pages.

Index

Constants

View Source
const DefaultAddr = "127.0.0.1:8081"

DefaultAddr is the address of the admin panel. It is a separate port so the panel can be kept off the public network.

Variables

This section is empty.

Functions

func AddPage

func AddPage(app *platform.App, p Page)

AddPage registers a project page in the admin panel.

func Auth

func Auth(app *platform.App) *adminx.Auth

Auth returns the sign in service from the container: project pages use it to know who is signed in.

func EnsureSchema

func EnsureSchema(ctx context.Context, pool *pgxpool.Pool) error

EnsureSchema creates the tables of the admin panel on the first run.

func NewAuditRepo

func NewAuditRepo(pool *pgxpool.Pool) adminx.AuditRepo

NewAuditRepo returns the audit log stored in PostgreSQL.

func NewServer

func NewServer(cfg Config, service string, auth *adminx.Auth, users adminx.UserRepo, aud adminx.AuditRepo, settings *settingsx.Store, pages []Page, log *slog.Logger) http.Handler

NewServer builds the panel handler. Everything it needs is passed in, so tests run it on in memory storage.

func NewSessionRepo

func NewSessionRepo(pool *pgxpool.Pool) adminx.SessionRepo

NewSessionRepo returns the sessions stored in PostgreSQL.

func NewUserRepo

func NewUserRepo(pool *pgxpool.Pool) adminx.UserRepo

NewUserRepo returns the accounts stored in PostgreSQL.

func UserFrom

func UserFrom(ctx context.Context) (adminx.User, bool)

UserFrom returns the signed in user of the request: project pages use it to know who is acting and what they may do.

Types

type Config

type Config struct {
	Addr       string        // listen address
	SessionTTL time.Duration // how long a session lives

	// Insecure allows the session cookie over plain HTTP. It is meant for local
	// development: in production the panel is behind TLS and the cookie is Secure.
	Insecure bool

	// BootstrapEmail and BootstrapPassword create the first account when the table is
	// empty. Without them a fresh installation has nobody to log in as.
	BootstrapEmail    string
	BootstrapPassword string
}

Config holds module settings. Load fills it from the environment; the platform generator writes the Load call into the project's config.gen.go.

func Load

func Load(l *confx.Loader) Config

Load reads the module settings from environment variables.

type Module

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

Module implements platform.Module.

func New

func New(cfg Config) *Module

New creates the module from ready settings.

func (*Module) Addr

func (m *Module) Addr() string

Addr is the address the panel actually listens on. With port 0 in the settings it is the port the system picked, which is what tests use.

func (*Module) Health

func (m *Module) Health(context.Context) error

Health reports whether the panel is serving.

func (*Module) Init

func (m *Module) Init(ctx context.Context, app *platform.App) error

Init prepares the storage and the sign in, and puts the page registry into the container so that wireDomain can add the project pages.

func (*Module) Name

func (m *Module) Name() string

func (*Module) Start

func (m *Module) Start(context.Context) error

Start serves the panel and begins removing expired sessions.

func (*Module) Stop

func (m *Module) Stop(ctx context.Context) error

Stop shuts the panel down.

type Page

type Page struct {
	Title   string       // name in the menu
	Path    string       // path inside the panel, "/orders"
	Roles   []string     // who may open it; empty means any signed in user
	Handler http.Handler // the page itself
}

Page is a project page in the admin panel. It is the extension point: the platform gives the layout, the sign in and the roles, the project gives the content.

type Registry

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

Registry holds the project pages. It lives in the container, and AddPage fills it from wireDomain, before the modules start.

func Pages

func Pages(app *platform.App) *Registry

Pages returns the page registry from the container.

func (*Registry) Add

func (r *Registry) Add(p Page)

Add registers a page.

func (*Registry) Pages

func (r *Registry) Pages() []Page

Pages returns the registered pages.

Jump to

Keyboard shortcuts

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