Documentation
¶
Overview ¶
Package demo runs GoHead as a public demo: visitors sign in with a shared account that can look at everything in the admin and edit content drafts, but not change settings, and the database goes back to a snapshot every night.
Index ¶
- Constants
- Variables
- func Configure(c Config) error
- func Enabled() bool
- func EnsureAccount() error
- func IsDemo(role string) bool
- func NextReset(now time.Time) (time.Time, bool)
- func RedactEmails(v any) any
- func Reset(ctx context.Context, after func()) error
- func Restore(ctx context.Context) error
- func Run(ctx context.Context, after func())
- func Snapshot(ctx context.Context) (time.Time, error)
- func SnapshotTime() (time.Time, bool)
- type Config
- type Info
Constants ¶
const Role = "demo"
Role is the role of the demo account.
Variables ¶
var ErrNoSnapshot = errors.New("no demo snapshot yet: take one with POST /admin/demo/snapshot")
ErrNoSnapshot is returned when no snapshot was taken yet.
var ErrNotSQLite = errors.New("demo snapshots need a SQLite database")
ErrNotSQLite is returned on databases other than SQLite: the demo reset copies SQLite tables.
var ErrSnapshotOutdated = errors.New("the database was migrated since the demo snapshot: take a new snapshot")
ErrSnapshotOutdated is returned when migrations ran since the snapshot.
Functions ¶
func EnsureAccount ¶
func EnsureAccount() error
EnsureAccount creates or updates the demo role and account: content read, create and update everywhere (no publish, no delete), media read.
func RedactEmails ¶
RedactEmails returns a response with every email address replaced: the demo account reads what the public site's forms collect, and the users' addresses.
func Reset ¶
Reset restores the snapshot and drops the caches; after runs once it worked (the GraphQL schema is rebuilt there).
func Restore ¶
Restore puts every table back as in the snapshot, in one transaction. Columns added since the snapshot keep their defaults.
func SnapshotTime ¶
SnapshotTime returns when the snapshot was taken.
Types ¶
type Config ¶
type Config struct {
Enabled bool
Username string
Password string
// ResetAt is the daily reset time, "HH:MM" UTC; "" never.
ResetAt string
// Snapshot is the file resets restore.
Snapshot string
}
Config is the demo settings.
type Info ¶
type Info struct {
Username string `json:"username"`
Password string `json:"password"`
ResetAt string `json:"resetAt,omitempty"`
NextAt *time.Time `json:"nextReset,omitempty"`
}
Info is what the login page shows: how to sign in, when it resets.
func PublicInfo ¶
PublicInfo returns the demo's sign-in details.