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
- func AddPage(app *platform.App, p Page)
- func Auth(app *platform.App) *adminx.Auth
- func EnsureSchema(ctx context.Context, pool *pgxpool.Pool) error
- func NewAuditRepo(pool *pgxpool.Pool) adminx.AuditRepo
- func NewServer(cfg Config, service string, auth *adminx.Auth, users adminx.UserRepo, ...) http.Handler
- func NewSessionRepo(pool *pgxpool.Pool) adminx.SessionRepo
- func NewUserRepo(pool *pgxpool.Pool) adminx.UserRepo
- func UserFrom(ctx context.Context) (adminx.User, bool)
- type Config
- type Module
- type Page
- type Registry
Constants ¶
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 Auth ¶
Auth returns the sign in service from the container: project pages use it to know who is signed in.
func EnsureSchema ¶
EnsureSchema creates the tables of the admin panel on the first run.
func NewAuditRepo ¶
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 ¶
NewUserRepo returns the accounts stored in PostgreSQL.
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.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module implements platform.Module.
func (*Module) Addr ¶
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) Init ¶
Init prepares the storage and the sign in, and puts the page registry into the container so that wireDomain can add the project pages.
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.