widgets

package
v0.0.0-...-a3392df Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Type string
	Item *Widget
	ID   string
}

type Options

type Options struct {
	Scope  []string
	Tenant string
	Q      string
	Limit  int
	Offset int
}

type RedisSubscriber

type RedisSubscriber struct {
	RDB          *redis.Client
	Channel      string
	Repo         Repo
	Reg          Registry
	Logger       *slog.Logger
	BackoffMS    int
	BackoffMaxMS int
}

RedisSubscriber consumes widget events from Redis and updates the registry.

func (*RedisSubscriber) Start

func (s *RedisSubscriber) Start(ctx context.Context) (stop func())

Start begins consuming events in a background goroutine.

type Registry

type Registry interface {
	List(ctx context.Context, opt Options) ([]Widget, int, string, time.Time, error)
	Upsert(ctx context.Context, w Widget) error
	Remove(ctx context.Context, id string) error
	ApplyDiff(ctx context.Context, upserts []Widget, removes []string) (string, time.Time, error)
	Subscribe() (<-chan Event, func())
	Has(id string) bool
	DefaultConfig(id string) []byte
}

func NewInMemory

func NewInMemory() Registry

type Repo

type Repo interface {
	GetByID(ctx context.Context, id string) (widgetsrepo.Row, error)
	List(ctx context.Context, f widgetsrepo.Filter) ([]widgetsrepo.Row, int, error)
}

Repo defines database operations required by the subscriber.

type Watcher

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

Watcher watches a directory of widget JSON files and applies changes to the registry.

func NewWatcher

func NewWatcher(dir string, reg Registry, debounce time.Duration, logger *slog.Logger) *Watcher

func (*Watcher) Start

func (w *Watcher) Start(ctx context.Context) (func(), error)

Start begins watching. Returns stop function.

type Widget

type Widget struct {
	ID           string         `json:"id"`
	Name         string         `json:"name"`
	Version      string         `json:"version"`
	Type         string         `json:"type"`
	Scopes       []string       `json:"scopes"`
	Enabled      bool           `json:"enabled"`
	Description  string         `json:"description,omitempty"`
	Capabilities []string       `json:"capabilities,omitempty"`
	Homepage     string         `json:"homepage,omitempty"`
	UpdatedAt    time.Time      `json:"updated_at"`
	Meta         map[string]any `json:"meta,omitempty"`
	Tenants      []string       `json:"-"`
}

func LoadAll

func LoadAll(dir string) ([]Widget, error)

LoadAll reads all widget JSON files within dir.

func LoadOne

func LoadOne(path string) (Widget, error)

LoadOne reads a single widget JSON file.

Jump to

Keyboard shortcuts

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