reloader

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: BSD-2-Clause Imports: 8 Imported by: 1 module, 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Reloader

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

Reloader holds the atomic request-dispatch handler that the HTTP server serves through, plus the SIGHUP-driven reload loop. On each successful SIGHUP the entire mux is rebuilt via CreateRouterFromConfig and atomically swapped; in-flight requests already inside the old handler tree finish against it. A failed reload leaves the old handler pointer intact.

func NewReloader

func NewReloader(
	cfgPath string,
	initial http.Handler,
	build func(ctx context.Context, cfg *pkg.Config) (http.Handler, error),
) *Reloader

NewReloader constructs the Reloader and stores initial via a snapshot.

func (*Reloader) ConfigSnapshot

func (r *Reloader) ConfigSnapshot() *pkg.Config

ConfigSnapshot returns the currently-active config. Used by prompt 2's tests to inspect the active config without racing the reload loop.

func (*Reloader) Reload

func (r *Reloader) Reload(ctx context.Context) error

Reload performs ONE reload attempt: loads the config, builds a new handler via r.build, and atomically swaps them together. Returns the error from Load or build; on error the old snapshot stays active (no Store call).

func (*Reloader) RunSighupLoop

func (r *Reloader) RunSighupLoop(ctx context.Context)

RunSighupLoop blocks until ctx is cancelled, handling SIGHUP. On each SIGHUP it calls r.Reload(ctx). A reload error is logged at WARNING with the message `config reload failed: <err>` and the old config is retained. A panic during reload is recovered (no goroutine leak, no process crash) and logged at ERROR. SIGHUP NEVER cancels ctx; only SIGINT/SIGTERM (handled by run.ContextWithSig upstream) cancel it.

func (*Reloader) SeedConfig

func (r *Reloader) SeedConfig(cfg *pkg.Config)

SeedConfig seeds the initial config for ConfigSnapshot before the first successful reload. Overwrites the handler's snapshot with one carrying cfg.

func (*Reloader) ServeHTTP

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

ServeHTTP loads the current handler and calls its ServeHTTP. This is the http.Handler that libhttp.NewServer dispatches through.

Jump to

Keyboard shortcuts

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