ui

package
v0.0.38 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 12 Imported by: 0

README

sup/ui

Go Reference Test License

sup/ui provides an out-of-the-box, beautifully designed web interface to observe the internal state of your actors. By strictly adhering to actor-model principles, the dashboard is read-only, ensuring that state mutation remains safely isolated within the actors themselves.

Features

  • Real-Time Updates: Uses Server-Sent Events (SSE) to instantly push state changes to the browser.
  • Zero Dependencies: No npm, no external CSS frameworks, no frontend build steps. The HTML, CSS, and JS are highly optimized and embedded directly into your Go binary using embed.FS.
  • Actor-Model Compliant: Purely observational. Actors broadcast their state, and the UI consumes it, preventing external UI mutations from violating actor concurrency guarantees.
  • Automatic Type Inference: Automatically detects whether an actor's state is a boolean, number, string, or json and formats it accordingly.

Installation

go get github.com/webermarci/sup/ui

Usage

Integrating the dashboard into your sup application takes only a few lines of code.

1. Create the Dashboard

Initialize the dashboard and register the providers (actors) you want to observe using ui.WithObserve().

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())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Card

type Card struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

Card represents a single card in the dashboard, with a name and a type.

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) 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](provider bus.Provider[V]) DashboardOption

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

Jump to

Keyboard shortcuts

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