golazy.dev golazy.dev / lazyworkers Index | Files

package lazyworkers

import "golazy.dev/lazyworkers"

Package lazyworkers registers browser worker scripts for GoLazy applications.

A Registry records service workers, dedicated web workers, shared workers, and future worker-like scripts in one place. It can serve generated scripts, expose template helpers for paths and registration snippets, and publish the registered inventory to lazydev tooling.

Conventional GoLazy applications get a Registry through lazyapp.Config. Packages such as lazypwa can register their own workers there, while applications can also register independent worker scripts directly. The package is still usable without lazyapp when a custom net/http stack wants to serve or inspect worker scripts.

Constants

const LazyDevWorkersPath

LazyDevWorkersPath is the app control-plane path for worker inventory.

const LazyDevWorkersPath = "/workers"

Functions

Types

type Kind

Kind describes the browser worker API a script is intended for.

type Kind string

type Option

Option configures a registered worker.

type Option func(*Worker)
func WithContentType

WithContentType sets the generated script content type.

func WithContentType(contentType string) Option
func WithDescription

WithDescription records human-readable worker purpose for tooling.

func WithDescription(description string) Option
func WithPWA

WithPWA marks a worker as owned by lazypwa.

func WithPWA() Option
func WithScope

WithScope sets a service-worker scope.

func WithScope(scope string) Option
func WithScriptType

WithScriptType sets the worker script type.

func WithScriptType(scriptType ScriptType) Option
func WithSource

WithSource records where the worker script is served from.

func WithSource(source Source) Option

type Registry

Registry owns registered worker metadata and generated script handlers.

type Registry struct {
	// contains filtered or unexported fields
}
func New

New creates an empty worker registry.

func New() *Registry
func (r *Registry) AddAsset

AddAsset records a worker script served by the application's asset registry.

func (r *Registry) AddAsset(name string, kind Kind, workerPath string, options ...Option) error
func (r *Registry) AddHandler

AddHandler registers a worker served by handler.

func (r *Registry) AddHandler(name string, kind Kind, workerPath string, handler http.Handler, options ...Option) error
func (r *Registry) AddScript

AddScript registers and serves generated worker script bytes.

func (r *Registry) AddScript(name string, kind Kind, workerPath string, script []byte, options ...Option) error
func (r *Registry) Empty

Empty reports whether no workers are registered.

func (r *Registry) Empty() bool
func (r *Registry) Handler

Handler serves generated worker scripts and falls through to next for misses.

func (r *Registry) Handler(next http.Handler) http.Handler
func (r *Registry) Helpers

Helpers returns lazyview-compatible worker helpers.

func (r *Registry) Helpers() map[string]any
func (r *Registry) Manifest

Manifest returns a stable snapshot of all registered workers.

func (r *Registry) Manifest() Manifest
func (r *Registry) MiddlewareName

MiddlewareName returns the dispatcher-visible middleware name.

func (r *Registry) MiddlewareName() string
func (r *Registry) Path

Path returns the registered URL path for name.

func (r *Registry) Path(name string) (string, error)
func (r *Registry) ServeHTTP

ServeHTTP serves generated worker scripts as a standalone handler.

func (r *Registry) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (r *Registry) Worker

Worker returns a registered worker by name.

func (r *Registry) Worker(name string) (Worker, bool)

type Worker

Worker describes one registered browser worker.

type Worker struct {
	Name		string		`json:"name"`
	Kind		Kind		`json:"kind"`
	Path		string		`json:"path"`
	Scope		string		`json:"scope,omitempty"`
	Type		ScriptType	`json:"type,omitempty"`
	Source		Source		`json:"source"`
	Description	string		`json:"description,omitempty"`
	ContentType	string		`json:"content_type,omitempty"`
	Generated	bool		`json:"generated,omitempty"`
	PWA		bool		`json:"pwa,omitempty"`
}