demo

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const Role = "demo"

Role is the role of the demo account.

Variables

View Source
var ErrNoSnapshot = errors.New("no demo snapshot yet: take one with POST /admin/demo/snapshot")

ErrNoSnapshot is returned when no snapshot was taken yet.

View Source
var ErrNotSQLite = errors.New("demo snapshots need a SQLite database")

ErrNotSQLite is returned on databases other than SQLite: the demo reset copies SQLite tables.

View Source
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 Configure

func Configure(c Config) error

Configure sets the demo settings (call at startup).

func Enabled

func Enabled() bool

Enabled reports whether the instance is a demo.

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 IsDemo

func IsDemo(role string) bool

IsDemo reports whether role is the demo account's, in demo mode.

func NextReset

func NextReset(now time.Time) (time.Time, bool)

NextReset returns the next reset after now.

func RedactEmails

func RedactEmails(v any) any

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

func Reset(ctx context.Context, after func()) error

Reset restores the snapshot and drops the caches; after runs once it worked (the GraphQL schema is rebuilt there).

func Restore

func Restore(ctx context.Context) error

Restore puts every table back as in the snapshot, in one transaction. Columns added since the snapshot keep their defaults.

func Run

func Run(ctx context.Context, after func())

Run resets the demo every day at demo.reset_at until ctx ends.

func Snapshot

func Snapshot(ctx context.Context) (time.Time, error)

Snapshot saves the database as it is now: resets go back to it.

func SnapshotTime

func SnapshotTime() (time.Time, bool)

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

func PublicInfo(now time.Time) Info

PublicInfo returns the demo's sign-in details.

Jump to

Keyboard shortcuts

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