devserver

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package devserver implements Margo's development-only site server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Listen

func Listen(host string, port int, explicit bool, listen ListenFunc) (net.Listener, int, error)

Listen selects and retains a listener for the development server.

func NewHandler

func NewHandler(store *SnapshotStore, broker *Broker) http.Handler

NewHandler serves the current in-memory snapshot and live-reload stream.

func Run

func Run(ctx context.Context, options Options) error

Run serves snapshots and serializes rebuilds until cancellation or failure.

func URL

func URL(host string, port int, basePath string) string

URL returns the browser URL for a selected listener and site base path.

Types

type Broker

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

Broker publishes successful build generations to connected browsers.

func NewBroker

func NewBroker() *Broker

NewBroker creates an empty live-reload broker.

func (*Broker) Publish

func (broker *Broker) Publish(generation uint64)

Publish advances the visible build generation and notifies subscribers.

func (*Broker) ServeHTTP

func (broker *Broker) ServeHTTP(writer http.ResponseWriter, request *http.Request)

ServeHTTP streams ready and reload events using Server-Sent Events.

type BuildEvent

type BuildEvent struct {
	Generation uint64
	Err        error
	Initial    bool
	Snapshot   Snapshot
}

BuildEvent reports one completed development build.

type Builder

type Builder interface {
	Build(context.Context) (Snapshot, error)
}

Builder produces one immutable site snapshot.

type ChangeSource

type ChangeSource interface {
	Changes() <-chan struct{}
	Errors() <-chan error
	Close() error
}

ChangeSource emits debounced filesystem changes and watcher failures.

func Watch

func Watch(root string, ignored func(string) bool, debounce time.Duration) (ChangeSource, error)

Watch recursively observes one project tree and emits debounced changes.

type ListenFunc

type ListenFunc func(network, address string) (net.Listener, error)

ListenFunc opens one network listener.

type Options

type Options struct {
	Listener      net.Listener
	URL           string
	Builder       Builder
	Changes       ChangeSource
	Store         *SnapshotStore
	Broker        *Broker
	Started       func(string)
	BuildReported func(BuildEvent)
}

Options configures one development server run.

type Snapshot

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

Snapshot is one immutable, HTTP-ready site build.

func NewSnapshot

func NewSnapshot(result site.Result) Snapshot

NewSnapshot copies a site result into an immutable serving snapshot.

func (Snapshot) ArtifactCount

func (snapshot Snapshot) ArtifactCount() int

ArtifactCount returns the number of generated artifacts.

func (Snapshot) BasePath

func (snapshot Snapshot) BasePath() string

BasePath returns the configured public path prefix.

func (Snapshot) PageCount

func (snapshot Snapshot) PageCount() int

PageCount returns the number of generated pages.

type SnapshotStore

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

SnapshotStore atomically exposes the last successful site build.

func NewSnapshotStore

func NewSnapshotStore() *SnapshotStore

NewSnapshotStore creates an empty serving store.

func (*SnapshotStore) Replace

func (store *SnapshotStore) Replace(snapshot Snapshot) uint64

Replace publishes a successful snapshot and returns its new generation.

func (*SnapshotStore) SetError

func (store *SnapshotStore) SetError(failure error)

SetError records a failed build without discarding a last-good snapshot.

Jump to

Keyboard shortcuts

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