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 ¶
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 ¶
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 ¶
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 ¶
SeedConfig seeds the initial config for ConfigSnapshot before the first successful reload. Overwrites the handler's snapshot with one carrying cfg.