ui

package
v0.0.47 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 15 Imported by: 0

README

sup/ui

Go Reference Test License

sup/ui provides a web-based dashboard to observe the internal state of your actors. The dashboard is intentionally read-only so that state mutation remains isolated inside the actors themselves and the UI only observes and displays state changes.

Features

  • Real-Time Updates: Uses Server-Sent Events (SSE) to push state changes to the browser in real time.
  • SvelteKit Frontend: The UI is implemented with SvelteKit and Vite for a modern, component-driven frontend.
  • Embeddable Static Assets: Built frontend assets are embedded into the Go binary using embed.FS. See sup/ui/frontend/frontend.go which contains //go:embed all:build and //go:generate directives.
  • Prebuilt: A build directory is included in the repository so you can compile and run the Go binary without having Node installed.
  • Actor-Model Compliant: The dashboard only observes and displays state; it does not mutate actor state.
  • Automatic Type Inference: Values are automatically shown as boolean, number, string, or json for nice formatting.

Installation

go get github.com/webermarci/sup/ui

Usage

Integrating the dashboard into your sup application requires only a few lines. The dashboard is just another supervised actor and exposes an http.Handler() that serves both the API and the frontend.

package main

import (
	"context"
	"net/http"

	"github.com/webermarci/sup"
	"github.com/webermarci/sup/ui"
)

func main() {
	// Assume you have some actors that implement bus.Provider
	sensorActor := NewSensorActor("temperature")
	statusActor := NewStatusActor("status")

	// Create the Dashboard actor and attach your providers
	dashboard := ui.NewDashboard("dashboard",
		ui.WithObserve(sensorActor),
		ui.WithObserve(statusActor),
	)

	// Create a supervisor and add your actors
	supervisor := sup.NewSupervisor("root",
		sup.WithActor(sensorActor),
		sup.WithActor(statusActor),
		sup.WithActor(dashboard), // The dashboard is just another supervised actor!
	)

	// Start the HTTP server to serve the UI
	go func() {
		http.ListenAndServe(":8080", dashboard.Handler())
	}()

	// Run the supervisor tree
	supervisor.Run(context.Background())
}

With the repository's prebuilt sup/ui/frontend/build present, the dashboard will serve the static site embedded in the binary.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dashboard

type Dashboard struct {
	*sup.BaseActor
	// contains filtered or unexported fields
}

Dashboard is an actor that serves a web-based dashboard for monitoring various providers and states.

func NewDashboard

func NewDashboard(name string, opts ...DashboardOption) *Dashboard

NewDashboard creates a new Dashboard instance with the given name and options.

func (*Dashboard) Handler

func (d *Dashboard) Handler() http.Handler

Handler returns an http.Handler that serves the dashboard API and frontend assets.

func (*Dashboard) Inspect added in v0.0.43

func (d *Dashboard) Inspect() sup.Spec

Inspect returns the specification.

func (*Dashboard) Run

func (d *Dashboard) Run(ctx context.Context) error

Run starts all dashboard streams and blocks until the context is canceled or a stream returns an error.

type DashboardOption

type DashboardOption func(*Dashboard)

DashboardOption represents a functional option for configuring the Dashboard. It allows adding providers to observe, which will be reflected in the real-time UI.

func WithObserve

func WithObserve[V any](signal sup.ReadableSignal[V]) DashboardOption

WithObserve adds a read-only row to the dashboard for the given signal. The dashboard will subscribe to the signal for updates and reflect changes in the UI, but will not allow user input to update the signal.

type Node added in v0.0.43

type Node struct {
	Name  string   `json:"name"`
	Spec  sup.Spec `json:"spec"`
	Type  string   `json:"type"`
	Value any      `json:"value"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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