configwait

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package configwait provides utilities for waiting on configuration availability during startup.

Index

Constants

View Source
const (
	EnvMaxRetries    = "CONFIG_WAIT_MAX_RETRIES"
	EnvRetryInterval = "CONFIG_WAIT_RETRY_INTERVAL"
)
View Source
const (
	DefaultMaxRetries    = 30
	DefaultRetryInterval = 2 * time.Second
)

Variables

This section is empty.

Functions

func Wait

func Wait(ctx context.Context, cfg Config, load LoadFunc) error

Wait blocks until load succeeds or max retries is reached.

Types

type Config

type Config struct {
	MaxRetries    int
	RetryInterval time.Duration
}

Config configures the wait behavior.

func NewConfigFromEnv

func NewConfigFromEnv() Config

NewConfigFromEnv creates a Config from environment variables.

type LoadFunc

type LoadFunc func(ctx context.Context) error

LoadFunc attempts to load configuration; returns nil on success.

type ReadyGate

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

ReadyGate gates HTTP requests until the service is ready.

func NewReadyGate

func NewReadyGate(inner http.Handler, allowedPaths []string) *ReadyGate

NewReadyGate creates a ReadyGate wrapping the given handler. The allowedPaths are path prefixes always allowed through (e.g., "/setup"). The inner handler can be nil initially; call SetHandler() once ready.

func (*ReadyGate) IsReady

func (rg *ReadyGate) IsReady() bool

IsReady returns true if the service is ready.

func (*ReadyGate) ServeHTTP

func (rg *ReadyGate) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

func (*ReadyGate) SetHandler

func (rg *ReadyGate) SetHandler(h http.Handler)

SetHandler sets the main handler to use once ready.

func (*ReadyGate) SetReady

func (rg *ReadyGate) SetReady()

SetReady marks the service as ready to handle all requests.

type ReloadFunc

type ReloadFunc func(ctx context.Context) error

ReloadFunc is called when a reload is triggered.

type Reloader

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

Reloader manages configuration reloading via SIGHUP or programmatic triggers.

func NewReloader

func NewReloader(ctx context.Context, gate *ReadyGate, reloadFunc ReloadFunc) *Reloader

NewReloader creates a Reloader that calls reloadFunc when triggered.

func (*Reloader) Start

func (r *Reloader) Start() <-chan struct{}

Start begins listening for SIGHUP signals and programmatic triggers. Returns a channel that closes when the reloader stops.

func (*Reloader) Trigger

func (r *Reloader) Trigger()

Trigger requests a configuration reload. Safe to call from any goroutine.

Jump to

Keyboard shortcuts

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