dev

package
v0.12.4 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAdminDevProxy

func NewAdminDevProxy(devURL string, apiHandler http.Handler) http.Handler

NewAdminDevProxy creates an http.Handler that proxies non-API /admin/ requests to the Vite dev server during development. API requests (/admin/api/) are served directly by huan, preserving the full API behavior.

Usage:

./huan serve --adminDev http://localhost:5173
cd web/admin && npm run dev   # separate terminal

Types

type LiveReloadHub

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

LiveReloadHub manages WebSocket connections from browser clients running livereload.js. It broadcasts reload and alert messages to all clients.

Each client has its own writer goroutine that serializes writes — required because coder/websocket forbids concurrent calls to Conn.Write per conn. Broadcasts are fan-out to per-client send channels, so slow clients don't block other clients or the broadcaster.

func NewHub

func NewHub() *LiveReloadHub

func (*LiveReloadHub) AcceptHTTP

func (h *LiveReloadHub) AcceptHTTP(w http.ResponseWriter, r *http.Request)

AcceptHTTP upgrades an HTTP request to a WebSocket and hands it to the hub. Convenience for wiring into a stdlib mux.

func (*LiveReloadHub) BroadcastAlert

func (h *LiveReloadHub) BroadcastAlert(message string)

BroadcastAlert shows an alert popup in connected browsers (used for build errors).

func (*LiveReloadHub) BroadcastReload

func (h *LiveReloadHub) BroadcastReload()

BroadcastReload notifies all clients to refresh the page.

func (*LiveReloadHub) ClientCount

func (h *LiveReloadHub) ClientCount() int

ClientCount returns the current number of connected clients (useful for tests/logging).

func (*LiveReloadHub) HandleConn

func (h *LiveReloadHub) HandleConn(ctx context.Context, c *websocket.Conn)

HandleConn runs the WebSocket lifecycle for one client: starts a writer goroutine, sends the hello message, then runs the read loop until the client disconnects or ctx is cancelled. Blocks until disconnect.

type RebuildQueue added in v0.11.20

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

RebuildQueue serializes rebuilds and merges changes received during a build. The callback handles its own build errors and must return normally.

func NewRebuildQueue added in v0.11.20

func NewRebuildQueue(rebuild func([]string)) *RebuildQueue

NewRebuildQueue creates a queue without starting any goroutines.

func (*RebuildQueue) Close added in v0.11.20

func (q *RebuildQueue) Close()

Close rejects new submissions while allowing accepted work to finish. It does not block and may be called from the rebuild callback.

func (*RebuildQueue) Submit added in v0.11.20

func (q *RebuildQueue) Submit(paths []string)

Submit accepts a change batch. nil requests a full rebuild and takes precedence over paths in the same pending batch; an empty non-nil slice does nothing. The idle caller runs builds synchronously until the queue is empty. While a build runs, submissions copy and merge paths, then return immediately. The callback may call Submit. Submissions after Close are ignored.

func (*RebuildQueue) Wait added in v0.11.20

func (q *RebuildQueue) Wait()

Wait blocks until the queue is idle. Call Close first when shutting down so no later submission can start another build. Do not call Wait in the callback.

type Server

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

Server serves the built site over HTTP.

func New

func New(opts ServerOptions) *Server

func (*Server) Run

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

Run blocks until ctx is cancelled or a SIGINT/SIGTERM arrives.

type ServerOptions

type ServerOptions struct {
	OutputDir    string
	Bind         string
	Port         string         // ":0" or "0" makes the OS pick a free port
	Hub          *LiveReloadHub // optional; if nil, /livereload route returns 404
	AdminHandler http.Handler   // optional; if non-nil, mounted at /admin/
	Logf         func(format string, args ...any)
}

ServerOptions configures a Server.

type Watcher

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

Watcher recursively watches SourceDir for changes and invokes OnChange after a debounce delay.

func NewWatcher

func NewWatcher(opts WatcherOptions) (*Watcher, error)

func (*Watcher) Run

func (w *Watcher) Run(ctx context.Context) error

type WatcherOptions

type WatcherOptions struct {
	SourceDir string
	Debounce  time.Duration
	OnChange  func()
	// OnChanges receives all unique changed paths and takes precedence over OnChange.
	OnChanges func([]string)
	Logf      func(format string, args ...any)
	// IgnoreDirs lists directories (relative to SourceDir, or absolute) that
	// are neither watched nor able to trigger rebuilds — e.g. the publish
	// output dir, which a concurrent `huan build` may rewrite.
	IgnoreDirs []string
}

WatcherOptions configures a Watcher.

Jump to

Keyboard shortcuts

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