config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Validate

func Validate(cfg Config) error

Validate validates config values.

Types

type Config

type Config struct {
	Address           string        `json:"address"`
	ReadTimeout       time.Duration `json:"read_timeout"`
	WriteTimeout      time.Duration `json:"write_timeout"`
	IdleTimeout       time.Duration `json:"idle_timeout"`
	ReadHeaderTimeout time.Duration `json:"read_header_timeout"`
	ShutdownTimeout   time.Duration `json:"shutdown_timeout"`
	MaxHeaderBytes    int           `json:"max_header_bytes"`

	TemplatesDir   string `json:"templates_dir"`
	LayoutTemplate string `json:"layout_template"`
	TemplateReload bool   `json:"template_reload"`

	LogLevel  string `json:"log_level"`
	LogFormat string `json:"log_format"`
}

Config holds app configuration.

func Default

func Default() Config

Default returns safe defaults.

func Load

func Load(path, envPrefix string) (Config, error)

Load loads config from file (if provided) and applies env overrides.

func LoadFromEnv

func LoadFromEnv(prefix string, base Config) Config

LoadFromEnv applies environment overrides with a prefix (e.g. BEBO_).

func LoadFromFile

func LoadFromFile(path string, base Config) (Config, error)

LoadFromFile loads configuration from a JSON file into the base config.

func LoadProfile

func LoadProfile(profile Profile) (Config, error)

LoadProfile loads Config from a layered profile with validation.

type Loader

type Loader[T any] struct {
	Defaults func() T
	ApplyEnv func(prefix string, base T) T
	Validate func(cfg T) error
}

Loader composes layered config with defaults and validation.

func (Loader[T]) Load

func (l Loader[T]) Load(profile Profile) (T, error)

Load merges profile layers into a typed config.

type Profile

type Profile struct {
	BasePath     string
	EnvPath      string
	SecretsPath  string
	EnvPrefix    string
	AllowMissing bool
}

Profile describes layered config sources.

Jump to

Keyboard shortcuts

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