loader

package
v0.51.2 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package loader provides primitives to load an applet both when the underlying file changes and on demand when an update is requested.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RenderApplet

func RenderApplet(ctx context.Context, path string, config map[string]any, options ...Option) ([]byte, []string, error)

Types

type ImageFormat

type ImageFormat int
const (
	ImageWebP ImageFormat = iota
	ImageGIF
	ImageAVIF
)

type Loader

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

Loader is a structure to provide applet loading when a file changes or on demand.

func NewLoader

func NewLoader(
	id string,
	root *os.Root,
	watch bool,
	fileChanges chan struct{},
	updatesChan chan Update,
	configOutFile string,
	options ...Option,
) (*Loader, error)

NewLoader instantiates a new loader structure. The loader will read off of fileChanges channel and write updates to the updatesChan. Updates are base64 encoded WebP strings. If watch is enabled, both file changes and on demand requests will send updates over the updatesChan.

func (*Loader) CallSchemaHandler

func (l *Loader) CallSchemaHandler(ctx context.Context, config map[string]any, handlerName, parameter string) (string, error)

func (*Loader) Close added in v0.48.0

func (l *Loader) Close() error

func (*Loader) GetMainFile added in v0.51.1

func (l *Loader) GetMainFile() string

func (*Loader) GetSchema

func (l *Loader) GetSchema() []byte

func (*Loader) LoadApplet

func (l *Loader) LoadApplet(config map[string]any) (string, error)

LoadApplet loads the applet on demand.

TODO: This method is thread safe, but has a pretty glaring race condition. If two callers request an update at the same time, they have the potential to get each others update. At the time of writing, this method is only called when you refresh a webpage during app development - so it doesn't seem likely that it's going to cause issues in the short term.

func (*Loader) Locale added in v0.49.0

func (l *Loader) Locale() language.Tag

func (*Loader) Location added in v0.49.0

func (l *Loader) Location() *time.Location

func (*Loader) Meta added in v0.49.0

func (l *Loader) Meta() canvas.Metadata

func (*Loader) Run

func (l *Loader) Run(ctx context.Context) error

Run executes the main loop. If there are config changes, those are recorded. If there is an on-demand request, it's processed and sent back to the caller and sent out as an update. If there is a file change, we update the applet and send out the update over the updatesChan.

func (*Loader) SetIs2x added in v0.49.0

func (l *Loader) SetIs2x(is2x bool)

func (*Loader) SetLocale added in v0.49.0

func (l *Loader) SetLocale(loc string) error

func (*Loader) SetTimezone added in v0.49.0

func (l *Loader) SetTimezone(tz string) error

type Option added in v0.49.0

type Option func(config *RenderConfig)

func WithFilters added in v0.49.0

func WithFilters(filters encode.RenderFilters) Option

func WithImageFormat added in v0.49.0

func WithImageFormat(imageFormat ImageFormat) Option

func WithLanguage added in v0.49.0

func WithLanguage(lang language.Tag) Option

func WithLocation added in v0.49.0

func WithLocation(location *time.Location) Option

func WithMaxDuration added in v0.49.0

func WithMaxDuration(maxDuration time.Duration) Option

func WithMeta added in v0.49.0

func WithMeta(meta canvas.Metadata) Option

func WithSilenceOutput added in v0.49.0

func WithSilenceOutput(silenceOutput bool) Option

func WithTimeout added in v0.49.0

func WithTimeout(timeout time.Duration) Option

type RenderConfig added in v0.49.0

type RenderConfig struct {
	Path          string
	Config        map[string]any
	Meta          canvas.Metadata
	MaxDuration   time.Duration
	Timeout       time.Duration
	ImageFormat   ImageFormat
	SilenceOutput bool
	Location      *time.Location
	Language      language.Tag
	Filters       encode.RenderFilters
}

func NewRenderConfig added in v0.49.0

func NewRenderConfig(path string, config map[string]any, options ...Option) *RenderConfig

type Update

type Update struct {
	canvas.Metadata

	Image     string
	ImageType string
	Schema    string
	Err       error
}

Jump to

Keyboard shortcuts

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