devkit

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package devkit runs an island app from a script, with no agent in the loop, for development: Go tests drive it with a headless browser, and a program under cmd/ serves it to try widgets by hand.

The Kit is an http.Handler serving one page with the island. Every page open renders a fresh island and, when App.Script is set, starts the script on it; Start, Continue and Stop act on the page opened last. What the script reports with ui.notify, and how each run ends, goes to App.Report.

func main() {
	kit, err := devkit.New(devkit.App{
		Island: neui.Island{
			Name:     "board",
			Template: func(slot gox.Comp) gox.Elem { return func(cur gox.Cursor) error { return cur.Comp(slot) } },
			Library: func(l neui.Library) error {
				return nekit.IslandRegisterForm(l)
			},
		},
		Script: `ui.root.set(ui.form({fields: [{type: "text", label: "Name", name: "name"}]})); while (true) ui.notify(ui.draw())`,
	})
	if err != nil {
		log.Fatal(err)
	}
	defer kit.Close()
	log.Fatal(http.ListenAndServe(":8080", kit))
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	// Island is rendered as the page's only content; an empty Name becomes
	// "island".
	Island neui.Island
	// Config limits the runs; zero fields take the defaults.
	Config api.IslandConfig
	// Files limits the workspace, such as the size of a file a form
	// uploads; zero fields take the defaults.
	Files api.FilesConfig
	// Dir is the workspace directory; empty uses a temporary one that Close
	// removes.
	Dir string
	// Script starts on every page open; empty starts nothing.
	Script string
	// Report receives what the runs report; nil prints it to stderr.
	Report func(Report)
}

App is the island the Kit serves and how it runs.

type Kit

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

Kit serves the island page and runs scripts on it.

func New

func New(a App) (*Kit, error)

New creates the Kit; Close releases its workspace.

func (*Kit) Close

func (k *Kit) Close() error

Close releases the workspace, removing it unless App.Dir was set.

func (*Kit) Continue

func (k *Kit) Continue(code string, interrupt bool) (uint, uint, error)

Continue queues code on the running app of the page opened last; interrupt drops the queue and stops the script that runs.

func (*Kit) ServeHTTP

func (k *Kit) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Kit) Start

func (k *Kit) Start(ctx context.Context, code string) (uint, uint, error)

Start starts code on the island of the page opened last, ending the run there, and returns the run's task id and the script number.

func (*Kit) Stop

func (k *Kit) Stop(ctx context.Context) error

Stop ends the running app of the page opened last and waits for it.

type Report

type Report struct {
	// Task is the run's id; 0 when a script failed to start.
	Task uint
	// Kind is "notify", "ok" or "error".
	Kind string
	// Data is the notification or the result.
	Data json.RawMessage
	// Meta is the notification's meta, such as its kind and script.
	Meta map[string]any
	// Err is the error the run ended or failed to start with.
	Err error
}

Report is a notification or the end of a run.

func (Report) String

func (r Report) String() string

Jump to

Keyboard shortcuts

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