appconfig

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package appconfig provides a small, incremental facade for parsing configuration into typed application settings.

The initial implementation is intentionally not “struct-first” in the sense of deriving layers from structs. Instead, callers explicitly register Glazed ParameterLayers and bind them to fields inside a grouped settings struct T.

See CONFIG-PARSER-001 for the design and implementation diary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LayerSlug

type LayerSlug string

LayerSlug is a distinct type to encourage declaring layer slugs as constants.

Example:

const RedisSlug appconfig.LayerSlug = "redis"

type Parser

type Parser[T any] struct {
	// contains filtered or unexported fields
}

Parser is an incremental config boundary: - callers register layers and bind them to sub-struct pointers inside T - Parse executes a configurable middleware chain and returns a populated T.

V1 hydration uses ParsedLayers.InitializeStruct, which means fields are only populated when the destination structs have explicit `glazed.parameter` tags.

func NewParser

func NewParser[T any](options ...ParserOption) (*Parser[T], error)

NewParser constructs a Parser for the grouped settings struct type T.

func (*Parser[T]) Parse

func (p *Parser[T]) Parse() (*T, error)

Parse runs the configured middleware chain and returns a populated T.

func (*Parser[T]) Register

func (p *Parser[T]) Register(slug LayerSlug, layer layers.ParameterLayer, bind func(*T) any) error

Register associates a layer slug and ParameterLayer with a binder that returns a pointer to the corresponding sub-struct inside the grouped settings struct T.

Invariants: - slug must be non-empty and unique - layer must be non-nil - bind must be non-nil - slug must match layer.GetSlug() (to avoid mismatches between registration keys and parsed layer keys)

type ParserOption

type ParserOption func(*parserOptions) error

ParserOption configures a Parser.

func WithCobra

func WithCobra(cmd *cobra.Command, args []string) ParserOption

WithCobra configures the Parser to read flags and positional arguments from a Cobra command.

The caller is responsible for ensuring Cobra has parsed the args (i.e. this is used from within a cobra Run/RunE/PreRun hook, or after Execute has parsed).

func WithConfigFiles

func WithConfigFiles(files ...string) ParserOption

WithConfigFiles configures config files to load (low -> high precedence).

func WithDefaults

func WithDefaults() ParserOption

WithDefaults appends the defaults middleware (lowest precedence in the typical chain).

func WithEnv

func WithEnv(prefix string) ParserOption

WithEnv enables parsing from environment variables using the given prefix.

func WithMiddlewares

func WithMiddlewares(middlewares ...cmd_middlewares.Middleware) ParserOption

WithMiddlewares injects additional middlewares into the parse chain.

NOTE: Middleware ordering is subtle; this is an escape hatch for advanced usage.

func WithValuesForLayers

func WithValuesForLayers(values map[string]map[string]interface{}) ParserOption

WithValuesForLayers configures programmatic values for layers (optional).

Jump to

Keyboard shortcuts

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