devserver

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: MIT Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package devserver implements tryck dev: it builds the site into memory, serves it, rebuilds on file changes and tells browsers to reload over a WebSocket.

Each build produces an immutable build.Site. Requests read the current one from an atomic pointer and a single builder goroutine swaps it, so the request path takes no locks and never sees a half-built site.

Index

Constants

View Source
const DefaultDebounce = 75 * time.Millisecond

DefaultDebounce is how long the builder waits for file events to settle.

View Source
const WSPath = "/__tryck/ws"

WSPath is where browsers connect for reload and error messages.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	ConfigPath     string           // config file to reload on change
	ConfigExplicit bool             // --config was given, so the file must exist
	Overrides      config.Overrides // applied after every config load
	Out            io.Writer        // diagnostics and status lines
	Logger         *slog.Logger     // debug logging; nil = silent
	Verbose        bool             // also print info diagnostics
	Debounce       time.Duration    // 0 = DefaultDebounce
	Plugins        []plugin.Plugin  // extra compiled-in plugins
}

Options configure a Server.

type Server

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

Server is the dev server. Create it with New, call Start, and serve Handler.

func New

func New(cfg *config.Config, opts Options) *Server

New returns a server for cfg, which must already be loaded with opts.Overrides applied.

func (*Server) Done

func (s *Server) Done() <-chan struct{}

Done is closed when the builder goroutine has stopped.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler serves the current site.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start builds the site once, then watches for changes until ctx ends. The first build is served even if it has errors, with the error overlay shown.

Jump to

Keyboard shortcuts

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