sandbox

package
v0.271.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 26 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 sandbox runs the playground on the CLI's embedded OpenFGA server, persisted in a SQLite file.

Index

Constants

View Source
const DBEnv = "OPENFGA_PLAYGROUND_DB"

DBEnv overrides the saved playground database location.

Variables

View Source
var ErrSchemaTooNew = errors.New("database schema is newer than this binary supports")

ErrSchemaTooNew is returned (wrapped) by OpenDatastore when the database was migrated by a newer binary than this one. The file is left untouched.

Functions

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns where the playground database is saved: $OPENFGA_PLAYGROUND_DB if set, else playground.db in the platform's per-user data directory.

func ExtractSamples

func ExtractSamples(dir string) (map[string]string, error)

ExtractSamples writes each embedded workspace to dir/<name> and returns name -> workspace root.

func OpenDatastore

func OpenDatastore(path string) (storage.OpenFGADatastore, error)

OpenDatastore opens (creating if needed) the SQLite database at path, applies the OpenFGA migrations embedded in this binary, and returns the SQLite datastore with metrics export off.

The returned datastore owns the underlying *sql.DB; callers release it by calling the datastore's Close(). If the database's migration version is above the newest embedded migration, OpenDatastore returns an error wrapping ErrSchemaTooNew before running any migration, so the file is not modified.

func SampleNames

func SampleNames() []string

SampleNames returns the sample store names in creation order.

Types

type Options

type Options struct {
	// SavedPath is the persisted playground database. It is only ever read
	// (copied) by Start and replaced atomically by Save.
	SavedPath string
	// Reset ignores an existing SavedPath and starts from the sample stores.
	Reset bool
}

Options configures Start.

type Session

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

Session is a playground running on a scratch copy of the database. Nothing reaches SavedPath unless Save is called.

func Start

func Start(ctx context.Context, o Options) (_ *Session, err error)

Start launches the embedded server on a scratch database: a copy of o.SavedPath if it exists (and !o.Reset), else a fresh database seeded with the sample stores. On any failure everything started is stopped and the scratch directory removed.

func (*Session) Close

func (s *Session) Close() error

Close stops everything and removes the scratch dir without saving. It is idempotent and safe after Save.

func (*Session) Dirty

func (s *Session) Dirty() bool

Dirty reports whether anything was successfully written since Start.

func (*Session) Endpoint

func (s *Session) Endpoint() string

Endpoint is the loopback URL of the playground's OpenFGA HTTP API.

func (*Session) Save

func (s *Session) Save() error

Save stops the server, then atomically replaces SavedPath with the scratch database and removes the scratch dir. On failure SavedPath is untouched.

func (*Session) Stop

func (s *Session) Stop() error

Stop stops the HTTP server, waiting for in-flight requests, and closes the engine, so Dirty reflects every write that will ever land. Save and Close still work afterwards; Stop is idempotent.

func (*Session) Workspaces

func (s *Session) Workspaces() map[string]*modeltest.Workspace

Workspaces maps each sample store name to its extracted workspace.

Jump to

Keyboard shortcuts

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