Documentation
¶
Overview ¶
Package useradmin provides a standalone user 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/blogadmin.
Index ¶
- Constants
- Variables
- type AdminInterface
- type AdminOptions
- type Country
- type FlashRedirectFunc
- type GeoResolverInterface
- type OnUserImpersonateFunc
- type OnUserSearchFunc
- type OnUserUpdatedFunc
- type SearchCombine
- type SearchCondition
- type SearchField
- type SearchOp
- type Timezone
- type UserPiiSealFunc
- type UserPiiUnsealFunc
- type UsersPiiUnsealFunc
Constants ¶
const ( SearchOpEquals = shared.SearchOpEquals SearchOpContains = shared.SearchOpContains SearchOpNotContains = shared.SearchOpNotContains SearchOpStartsWith = shared.SearchOpStartsWith )
Search operator constants.
const ( SearchFieldFirstName = shared.SearchFieldFirstName SearchFieldLastName = shared.SearchFieldLastName SearchFieldEmail = shared.SearchFieldEmail SearchFieldPhone = shared.SearchFieldPhone SearchFieldBusinessName = shared.SearchFieldBusinessName )
Search field constants.
const ( SearchAnd = shared.SearchAnd SearchOr = shared.SearchOr )
Search combinator constants.
Variables ¶
var ( // ErrUserStoreRequired is returned when UserStore is not provided ErrUserStoreRequired = errors.New("user store is required") // ErrLoggerRequired is returned when Logger is not provided ErrLoggerRequired = errors.New("logger is required") // ErrGeoResolverRequired is returned when GeoResolver is not // provided. The user update controller needs it to list countries // and timezones. ErrGeoResolverRequired = errors.New("geo resolver is required for the user update controller") )
Common errors
Functions ¶
This section is empty.
Types ¶
type AdminInterface ¶
type AdminInterface interface {
Handle(w http.ResponseWriter, r *http.Request)
}
AdminInterface defines the interface for the user admin
func New ¶
func New(opts AdminOptions) (AdminInterface, error)
New creates a new user admin instance. Returns ErrUserStoreRequired if UserStore is nil, ErrLoggerRequired if Logger is nil, ErrGeoResolverRequired if GeoResolver is nil.
OnUserImpersonate is optional — when nil, the impersonate button is hidden and the impersonate route returns 404.
This makes misconfiguration fail fast at construction instead of surfacing as runtime errors inside individual controllers.
type AdminOptions ¶
type AdminOptions struct {
// UserStore is required
UserStore userstore.StoreInterface
// GeoResolver is required for the user update controller (country
// and timezone lists).
GeoResolver shared.GeoResolverInterface
// Logger is required
Logger *slog.Logger
// OnUserImpersonate is optional — when nil, the impersonate
// button is hidden and the impersonate route is not registered.
// The host owns the auth mechanism (session+cookie, JWT, etc.).
OnUserImpersonate shared.OnUserImpersonateFunc
// OnUserSearch is an optional callback for custom user search
// (e.g. blind index, Elasticsearch). When nil, useradmin falls
// back to userstore query-based search.
OnUserSearch shared.OnUserSearchFunc
// OnUserUpdated is an optional callback invoked after a user is
// updated. The host can use it to trigger side effects (blind
// index rebuild, audit log, notifications, etc.). When nil, the
// callback is skipped.
OnUserUpdated shared.OnUserUpdatedFunc
// UserPiiSeal transforms a user from display representation to
// storage representation (e.g. tokenize, encrypt PII). Optional —
// when nil, the user is stored as-is (plain text).
UserPiiSeal shared.UserPiiSealFunc
// UserPiiUnseal transforms a user from storage representation to
// display representation (e.g. detokenize, decrypt PII). Optional —
// when nil, the user is used as-is (plain text).
UserPiiUnseal shared.UserPiiUnsealFunc
// UsersPiiUnseal is the batch version of UserPiiUnseal. It allows
// the host to unseal all users in a single call for efficiency.
// Optional — when nil, useradmin falls back to UserPiiUnseal per
// user (or plain text when that is also nil).
UsersPiiUnseal shared.UsersPiiUnsealFunc
// FlashRedirect redirects with a flash message. Optional — when
// nil, plain http.Redirect is used.
FlashRedirect shared.FlashRedirectFunc
// 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.
FuncLayout func(w http.ResponseWriter, r *http.Request, title string, body string, options struct {
Styles []string
StyleURLs []string
Scripts []string
ScriptURLs []string
}) string
// AdminHomeURL is the URL for the admin home page (default: "/admin")
AdminHomeURL string
// UserAdminURL is the base URL for the user admin (default: "/admin/users")
UserAdminURL string
// UserHomeURL is the URL the impersonate controller redirects to
// after a successful impersonation (default: "/"). This is where
// the impersonated user lands.
UserHomeURL string
}
AdminOptions contains all dependencies and configuration for the user admin.
UserStore, GeoResolver, and Logger are required. SessionStore is required for the impersonate controller. Blind index stores, UserPiiSeal/UserPiiUnseal/UsersPiiUnseal are optional — when nil, corresponding features degrade gracefully (filtered search disabled, email-change rebuild skipped, user fields treated as plain text).
FuncLayout is an optional function to render the admin interface inside your own layout (branding, menus, etc.). If nil, a default bare-bones HTML page is used (Bootstrap + Vue CDN). Uses an anonymous struct to match blogadmin/shopadmin exactly, so consumers can reuse their existing layout function for useradmin.
type Country ¶ added in v0.2.0
Re-exports of shared types so consumers can import everything from the top-level useradmin package without reaching into useradmin/shared. Follows the blogadmin/shopadmin convention (e.g. shopadmin.CustomerResolverInterface).
type FlashRedirectFunc ¶ added in v0.2.0
type FlashRedirectFunc = shared.FlashRedirectFunc
Re-exports of shared types so consumers can import everything from the top-level useradmin package without reaching into useradmin/shared. Follows the blogadmin/shopadmin convention (e.g. shopadmin.CustomerResolverInterface).
type GeoResolverInterface ¶ added in v0.2.0
type GeoResolverInterface = shared.GeoResolverInterface
Re-exports of shared types so consumers can import everything from the top-level useradmin package without reaching into useradmin/shared. Follows the blogadmin/shopadmin convention (e.g. shopadmin.CustomerResolverInterface).
type OnUserImpersonateFunc ¶ added in v0.2.0
type OnUserImpersonateFunc = shared.OnUserImpersonateFunc
Re-exports of shared types so consumers can import everything from the top-level useradmin package without reaching into useradmin/shared. Follows the blogadmin/shopadmin convention (e.g. shopadmin.CustomerResolverInterface).
type OnUserSearchFunc ¶ added in v0.2.0
type OnUserSearchFunc = shared.OnUserSearchFunc
Re-exports of shared types so consumers can import everything from the top-level useradmin package without reaching into useradmin/shared. Follows the blogadmin/shopadmin convention (e.g. shopadmin.CustomerResolverInterface).
type OnUserUpdatedFunc ¶ added in v0.2.0
type OnUserUpdatedFunc = shared.OnUserUpdatedFunc
Re-exports of shared types so consumers can import everything from the top-level useradmin package without reaching into useradmin/shared. Follows the blogadmin/shopadmin convention (e.g. shopadmin.CustomerResolverInterface).
type SearchCombine ¶ added in v0.2.0
type SearchCombine = shared.SearchCombine
Re-exports of shared types so consumers can import everything from the top-level useradmin package without reaching into useradmin/shared. Follows the blogadmin/shopadmin convention (e.g. shopadmin.CustomerResolverInterface).
type SearchCondition ¶ added in v0.2.0
type SearchCondition = shared.SearchCondition
Re-exports of shared types so consumers can import everything from the top-level useradmin package without reaching into useradmin/shared. Follows the blogadmin/shopadmin convention (e.g. shopadmin.CustomerResolverInterface).
type SearchField ¶ added in v0.2.0
type SearchField = shared.SearchField
Re-exports of shared types so consumers can import everything from the top-level useradmin package without reaching into useradmin/shared. Follows the blogadmin/shopadmin convention (e.g. shopadmin.CustomerResolverInterface).
type SearchOp ¶ added in v0.2.0
Re-exports of shared types so consumers can import everything from the top-level useradmin package without reaching into useradmin/shared. Follows the blogadmin/shopadmin convention (e.g. shopadmin.CustomerResolverInterface).
type Timezone ¶ added in v0.2.0
Re-exports of shared types so consumers can import everything from the top-level useradmin package without reaching into useradmin/shared. Follows the blogadmin/shopadmin convention (e.g. shopadmin.CustomerResolverInterface).
type UserPiiSealFunc ¶ added in v0.2.0
type UserPiiSealFunc = shared.UserPiiSealFunc
Re-exports of shared types so consumers can import everything from the top-level useradmin package without reaching into useradmin/shared. Follows the blogadmin/shopadmin convention (e.g. shopadmin.CustomerResolverInterface).
type UserPiiUnsealFunc ¶ added in v0.2.0
type UserPiiUnsealFunc = shared.UserPiiUnsealFunc
Re-exports of shared types so consumers can import everything from the top-level useradmin package without reaching into useradmin/shared. Follows the blogadmin/shopadmin convention (e.g. shopadmin.CustomerResolverInterface).
type UsersPiiUnsealFunc ¶ added in v0.2.0
type UsersPiiUnsealFunc = shared.UsersPiiUnsealFunc
Re-exports of shared types so consumers can import everything from the top-level useradmin package without reaching into useradmin/shared. Follows the blogadmin/shopadmin convention (e.g. shopadmin.CustomerResolverInterface).