config

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package config provides explicit, typed environment config helpers for modkit modules.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewModule

func NewModule(opts ...Option) module.Module

NewModule builds a regular modkit module that provides config values.

func ParseBool

func ParseBool(raw string) (bool, error)

ParseBool parses a bool value.

func ParseCSV

func ParseCSV(raw string) ([]string, error)

ParseCSV parses a comma-separated list. Empty entries are dropped.

func ParseDuration

func ParseDuration(raw string) (time.Duration, error)

ParseDuration parses a time.Duration value.

func ParseFloat64

func ParseFloat64(raw string) (float64, error)

ParseFloat64 parses a float64 value.

func ParseInt

func ParseInt(raw string) (int, error)

ParseInt parses an int value.

func ParseString

func ParseString(raw string) (string, error)

ParseString parses a string value.

Types

type InvalidSpecError

type InvalidSpecError struct {
	Token  module.Token
	Reason string
}

InvalidSpecError reports an invalid value specification.

func (*InvalidSpecError) Error

func (e *InvalidSpecError) Error() string

type MissingRequiredError

type MissingRequiredError struct {
	Key       string
	Token     module.Token
	Sensitive bool
}

MissingRequiredError reports a required key that was unset.

func (*MissingRequiredError) Error

func (e *MissingRequiredError) Error() string

type Option

type Option func(*builder)

Option configures the config module builder.

func WithModuleName

func WithModuleName(name string) Option

WithModuleName sets an explicit module name.

func WithSource

func WithSource(src Source) Option

WithSource sets a custom key lookup source.

func WithTyped

func WithTyped[T any](token module.Token, spec ValueSpec[T], export bool) Option

WithTyped registers a typed config provider.

type ParseError

type ParseError struct {
	Key       string
	Token     module.Token
	Type      string
	Sensitive bool
	Err       error
}

ParseError reports a value parse failure.

func (*ParseError) Error

func (e *ParseError) Error() string

func (*ParseError) Unwrap

func (e *ParseError) Unwrap() error

type Source

type Source interface {
	Lookup(key string) (value string, ok bool)
}

Source resolves a config key to a raw string value.

type ValueSpec

type ValueSpec[T any] struct {
	Key         string
	Required    bool
	Default     *T
	Sensitive   bool
	Description string
	Parse       func(raw string) (T, error)
}

ValueSpec defines how to resolve and parse a typed config value.

Jump to

Keyboard shortcuts

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