Documentation
¶
Overview ¶
Package bconf provides a package-scoped configuration management system for Go applications. It supports multiple configuration sources including environment variables, command-line flags, JSON files, and YAML files, with type-safe access to configuration values.
Index ¶
- Constants
- func FieldTypes() []string
- type AppConfig
- func (c *AppConfig) AddFieldSet(fieldSet *FieldSet)
- func (c *AppConfig) AddFieldSetGroup(groupName string, fieldSets FieldSets)
- func (c *AppConfig) AppDescription() string
- func (c *AppConfig) AppID() string
- func (c *AppConfig) AppName() string
- func (c *AppConfig) AppVersion() string
- func (c *AppConfig) AttachConfigStructs(configStructs ...any)
- func (c *AppConfig) ConfigMap() map[string]map[string]any
- func (c *AppConfig) FillStruct(configStruct any) (err error)
- func (c *AppConfig) GetBool(fieldSetKey, fieldKey string) (bool, error)
- func (c *AppConfig) GetBools(fieldSetKey, fieldKey string) ([]bool, error)
- func (c *AppConfig) GetDuration(fieldSetKey, fieldKey string) (time.Duration, error)
- func (c *AppConfig) GetDurations(fieldSetKey, fieldKey string) ([]time.Duration, error)
- func (c *AppConfig) GetField(fieldSetKey, fieldKey string) (*Field, error)
- func (c *AppConfig) GetInt(fieldSetKey, fieldKey string) (int, error)
- func (c *AppConfig) GetInts(fieldSetKey, fieldKey string) ([]int, error)
- func (c *AppConfig) GetMapStringAny(fieldSetKey, fieldKey string) (map[string]any, error)
- func (c *AppConfig) GetMapStringString(fieldSetKey, fieldKey string) (map[string]string, error)
- func (c *AppConfig) GetString(fieldSetKey, fieldKey string) (string, error)
- func (c *AppConfig) GetStrings(fieldSetKey, fieldKey string) ([]string, error)
- func (c *AppConfig) GetTime(fieldSetKey, fieldKey string) (time.Time, error)
- func (c *AppConfig) GetTimes(fieldSetKey, fieldKey string) ([]time.Time, error)
- func (c *AppConfig) HelpString() string
- func (c *AppConfig) Load(options ...LoadOption) []error
- func (c *AppConfig) SetField(fieldSetKey, fieldKey string, fieldValue any) error
- func (c *AppConfig) Warnings() []string
- type ConfigOption
- func WithAppID(appID string) ConfigOption
- func WithAppIDFunc(appIDFunc func() string) ConfigOption
- func WithAppVersion(appVersion string) ConfigOption
- func WithAppVersionFunc(appVersionFunc func() string) ConfigOption
- func WithEnvironmentLoader(keyPrefix ...string) ConfigOption
- func WithFlagLoader(keyPrefix ...string) ConfigOption
- type ConfigStruct
- type EnvironmentLoader
- func (l *EnvironmentLoader) Clone() *EnvironmentLoader
- func (l *EnvironmentLoader) CloneLoader() Loader
- func (l *EnvironmentLoader) Get(fieldSetKey, fieldKey string) (any, bool)
- func (l *EnvironmentLoader) GetMap(fieldSetKey string, fieldKeys []string) map[string]any
- func (l *EnvironmentLoader) HelpString(fieldSetKey, fieldKey string) string
- func (l *EnvironmentLoader) Name() string
- type Field
- type FieldBuilder
- type FieldLocation
- type FieldLocations
- type FieldSet
- type FieldSetBuilder
- type FieldSetStruct
- type FieldSets
- type FieldValidator
- func ValidateAll(validators ...FieldValidator) FieldValidator
- func ValidateAny(validators ...FieldValidator) FieldValidator
- func ValidateDirExists() FieldValidator
- func ValidateEachInt(validator FieldValidator) FieldValidator
- func ValidateEachString(validator FieldValidator) FieldValidator
- func ValidateFileExists() FieldValidator
- func ValidateIntMax(maxVal int) FieldValidator
- func ValidateIntMin(minVal int) FieldValidator
- func ValidateIntRange(minVal, maxVal int) FieldValidator
- func ValidateNonEmptySlice() FieldValidator
- func ValidateNonEmptyString() FieldValidator
- func ValidatePathExists() FieldValidator
- func ValidatePort() FieldValidator
- func ValidateSliceMaxLength(maxLen int) FieldValidator
- func ValidateSliceMinLength(minLen int) FieldValidator
- func ValidateStringMaxLength(maxLen int) FieldValidator
- func ValidateStringMinLength(minLen int) FieldValidator
- func ValidateStringRegex(pattern string) FieldValidator
- func ValidateURL() FieldValidator
- func ValidateURLWithSchemes(schemes ...string) FieldValidator
- type FieldValue
- type FieldValueFinder
- type FieldValues
- type Fields
- type FlagLoader
- func (l *FlagLoader) Clone() *FlagLoader
- func (l *FlagLoader) CloneLoader() Loader
- func (l *FlagLoader) Get(fieldSetKey, fieldKey string) (any, bool)
- func (l *FlagLoader) GetMap(fieldSetKey string, fieldKeys []string) map[string]any
- func (l *FlagLoader) HelpString(fieldSetKey, fieldKey string) string
- func (l *FlagLoader) Name() string
- type JSONFileLoader
- func (l *JSONFileLoader) Clone() *JSONFileLoader
- func (l *JSONFileLoader) CloneLoader() Loader
- func (l *JSONFileLoader) Get(fieldSetKey, fieldKey string) (any, bool)
- func (l *JSONFileLoader) GetMap(fieldSetKey string, fieldKeys []string) map[string]any
- func (l *JSONFileLoader) HelpString(fieldSetKey, fieldKey string) string
- func (l *JSONFileLoader) Name() string
- type JSONLoaderConfigOption
- type JSONUnmarshal
- type LoadCondition
- type LoadConditionBuilder
- type LoadConditions
- type LoadOption
- type Loader
- type LoaderKeyOverride
- type YAMLFileLoader
- func (l *YAMLFileLoader) Clone() *YAMLFileLoader
- func (l *YAMLFileLoader) CloneLoader() Loader
- func (l *YAMLFileLoader) Get(fieldSetKey, fieldKey string) (any, bool)
- func (l *YAMLFileLoader) GetMap(fieldSetKey string, fieldKeys []string) map[string]any
- func (l *YAMLFileLoader) HelpString(fieldSetKey, fieldKey string) string
- func (l *YAMLFileLoader) Name() string
- type YAMLFileLoaderOption
- type YAMLUnmarshal
Constants ¶
const ( Bool = "bool" Bools = "[]bool" String = "string" Strings = "[]string" Int = "int" Ints = "[]int" Float = "float64" Floats = "[]float64" Time = "time.Time" Times = "[]time.Time" Duration = "time.Duration" Durations = "[]time.Duration" MapStringAny = "map[string]any" MapStringString = "map[string]string" )
Field type constants for configuration field definitions.
const FieldNotFoundError = "field not found"
FieldNotFoundError is the error message returned when a field is not found.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AppConfig ¶
type AppConfig struct {
// contains filtered or unexported fields
}
AppConfig manages application configuration field-sets and provides access to configuration values. It should be initialized with the NewAppConfig function.
func NewAppConfig ¶
func NewAppConfig(appName, appDescription string, options ...ConfigOption) *AppConfig
NewAppConfig creates a new application configuration struct with configuration options that allow for the specification of configuration sources (environment, flags, json files, etc).
func (*AppConfig) AddFieldSet ¶
AddFieldSet adds a single field set to the configuration.
func (*AppConfig) AddFieldSetGroup ¶
AddFieldSetGroup adds a named group of field sets to the configuration.
func (*AppConfig) AppDescription ¶
AppDescription returns the configured application description.
func (*AppConfig) AppVersion ¶
AppVersion returns the configured application version.
func (*AppConfig) AttachConfigStructs ¶
AttachConfigStructs attaches struct pointers that will be filled with configuration values during Load.
func (*AppConfig) ConfigMap ¶
ConfigMap returns a nested map of all configuration values organized by field set and field key.
func (*AppConfig) FillStruct ¶
FillStruct populates a struct's fields with configuration values based on bconf tags.
func (*AppConfig) GetDuration ¶
GetDuration retrieves a time.Duration field value.
func (*AppConfig) GetDurations ¶
GetDurations retrieves a time.Duration slice field value.
func (*AppConfig) GetMapStringAny ¶ added in v0.7.0
GetMapStringAny retrieves a map[string]any field value.
func (*AppConfig) GetMapStringString ¶ added in v0.7.0
GetMapStringString retrieves a map[string]string field value.
func (*AppConfig) GetStrings ¶
GetStrings retrieves a string slice field value.
func (*AppConfig) HelpString ¶
HelpString returns a formatted help string describing all configuration options.
func (*AppConfig) Load ¶
func (c *AppConfig) Load(options ...LoadOption) []error
Load loads configuration values from all configured loaders and validates fields.
type ConfigOption ¶
type ConfigOption interface {
ConfigOptionType() string
}
ConfigOption is the interface for application configuration options passed to NewAppConfig.
func WithAppIDFunc ¶
func WithAppIDFunc(appIDFunc func() string) ConfigOption
WithAppIDFunc sets a function to generate the application ID dynamically.
func WithAppVersion ¶
func WithAppVersion(appVersion string) ConfigOption
WithAppVersion sets a static application version.
func WithAppVersionFunc ¶
func WithAppVersionFunc(appVersionFunc func() string) ConfigOption
WithAppVersionFunc sets a function to generate the application version dynamically.
func WithEnvironmentLoader ¶
func WithEnvironmentLoader(keyPrefix ...string) ConfigOption
WithEnvironmentLoader enables the Environment loader. Only the first value in the keyPrefix parameter will be accepted as a key prefix.
func WithFlagLoader ¶
func WithFlagLoader(keyPrefix ...string) ConfigOption
WithFlagLoader enables the Flag loader. Only the first value in the keyPrefix parameter will be accepted as a key prefix.
type ConfigStruct ¶
type ConfigStruct struct {
FieldSet string
}
ConfigStruct is embedded in structs that will be filled with configuration values.
type EnvironmentLoader ¶
type EnvironmentLoader struct {
KeyPrefix string
}
EnvironmentLoader loads configuration values from environment variables.
func NewEnvironmentLoader ¶
func NewEnvironmentLoader() *EnvironmentLoader
NewEnvironmentLoader creates a new environment loader without a key prefix.
func NewEnvironmentLoaderWithKeyPrefix ¶
func NewEnvironmentLoaderWithKeyPrefix(keyPrefix string) *EnvironmentLoader
NewEnvironmentLoaderWithKeyPrefix creates a new environment loader with the specified key prefix.
func (*EnvironmentLoader) Clone ¶
func (l *EnvironmentLoader) Clone() *EnvironmentLoader
Clone creates a copy of the EnvironmentLoader.
func (*EnvironmentLoader) CloneLoader ¶
func (l *EnvironmentLoader) CloneLoader() Loader
CloneLoader creates a copy of the loader as a Loader interface.
func (*EnvironmentLoader) Get ¶
func (l *EnvironmentLoader) Get(fieldSetKey, fieldKey string) (any, bool)
Get retrieves a single field value from environment variables.
func (*EnvironmentLoader) GetMap ¶
func (l *EnvironmentLoader) GetMap(fieldSetKey string, fieldKeys []string) map[string]any
GetMap retrieves multiple field values from environment variables.
func (*EnvironmentLoader) HelpString ¶
func (l *EnvironmentLoader) HelpString(fieldSetKey, fieldKey string) string
HelpString returns a help string describing where this field can be configured.
func (*EnvironmentLoader) Name ¶
func (l *EnvironmentLoader) Name() string
Name returns the name of this loader.
type Field ¶
type Field struct {
// Validator defines a function that runs during validation to check a value against validity constraints
Validator func(value any) error
// DefaultGenerator defines a function that creates a base value for a field
DefaultGenerator func() (any, error)
// Default defines a base value for a field
Default any
// Key is a required field that defines the field lookup value
Key string
// Type is a required field that defines the type of value the field contains
Type string
// Description defines a summary of the field contents
Description string
// Enumeration defines a list of acceptable inputs for the field value
Enumeration []any
// LoadConditions defines the conditions required for a field to load values
LoadConditions LoadConditions
// Required defines whether a field value must be set in order for the field to be valid
Required bool
// Sensitive identifies the field value as sensitive
Sensitive bool
// contains filtered or unexported fields
}
Field is a data structure that provides context for a configuration value
type FieldBuilder ¶
type FieldBuilder interface {
Default(value any) FieldBuilder
Validator(validationFunc func(fieldValue any) error) FieldBuilder
DefaultGenerator(defaultGeneratorFunc func() (any, error)) FieldBuilder
LoadConditions(conditions ...LoadCondition) FieldBuilder
Description(description string, concat ...string) FieldBuilder
Enumeration(acceptedValues ...any) FieldBuilder
Required() FieldBuilder
Sensitive() FieldBuilder
Create() *Field
C() *Field
}
FieldBuilder provides a fluent interface for constructing Field instances.
func FB ¶
func FB(fieldKey, fieldType string) FieldBuilder
FB is a shorthand alias for NewFieldBuilder.
func NewFieldBuilder ¶
func NewFieldBuilder(fieldKey, fieldType string) FieldBuilder
NewFieldBuilder creates a new field builder with the specified key and type.
type FieldLocation ¶
FieldLocation identifies a specific field by its field set key and field key.
func FD ¶
func FD(fieldSetKey, fieldKey string) FieldLocation
FD creates a FieldLocation with the specified field set key and field key.
type FieldLocations ¶
type FieldLocations []FieldLocation
FieldLocations is a slice of FieldLocation.
type FieldSet ¶
type FieldSet struct {
Key string
LoadConditions LoadConditions
Fields Fields
// contains filtered or unexported fields
}
FieldSet represents a group of related configuration fields.
type FieldSetBuilder ¶
type FieldSetBuilder interface {
Fields(fields ...*Field) FieldSetBuilder
LoadConditions(conditions ...LoadCondition) FieldSetBuilder
Create() *FieldSet
C() *FieldSet
}
FieldSetBuilder provides a fluent interface for constructing FieldSet instances.
func FSB ¶
func FSB(fieldSetKey string) FieldSetBuilder
FSB is a shorthand alias for NewFieldSetBuilder.
func NewFieldSetBuilder ¶
func NewFieldSetBuilder(fieldSetKey string) FieldSetBuilder
NewFieldSetBuilder creates a new field set builder with the specified key.
type FieldSetStruct ¶
type FieldSetStruct interface {
FieldSet() string
}
FieldSetStruct is implemented by structs that provide their field set key.
type FieldValidator ¶ added in v0.7.0
FieldValidator is the function signature for field validation.
func ValidateAll ¶ added in v0.7.0
func ValidateAll(validators ...FieldValidator) FieldValidator
ValidateAll returns a validator that passes only if all provided validators pass.
func ValidateAny ¶ added in v0.7.0
func ValidateAny(validators ...FieldValidator) FieldValidator
ValidateAny returns a validator that passes if at least one validator passes. If all validators fail, returns the error from the last validator.
func ValidateDirExists ¶ added in v0.7.0
func ValidateDirExists() FieldValidator
ValidateDirExists returns a validator that ensures a directory exists at the given path.
func ValidateEachInt ¶ added in v0.7.0
func ValidateEachInt(validator FieldValidator) FieldValidator
ValidateEachInt returns a validator that applies the given validator to each element in a []int.
func ValidateEachString ¶ added in v0.7.0
func ValidateEachString(validator FieldValidator) FieldValidator
ValidateEachString returns a validator that applies the given validator to each element in a []string.
func ValidateFileExists ¶ added in v0.7.0
func ValidateFileExists() FieldValidator
ValidateFileExists returns a validator that ensures a file exists at the given path.
func ValidateIntMax ¶ added in v0.7.0
func ValidateIntMax(maxVal int) FieldValidator
ValidateIntMax returns a validator that ensures an int is at most maxVal.
func ValidateIntMin ¶ added in v0.7.0
func ValidateIntMin(minVal int) FieldValidator
ValidateIntMin returns a validator that ensures an int is at least minVal.
func ValidateIntRange ¶ added in v0.7.0
func ValidateIntRange(minVal, maxVal int) FieldValidator
ValidateIntRange returns a validator that ensures an int is within [minVal, maxVal].
func ValidateNonEmptySlice ¶ added in v0.7.0
func ValidateNonEmptySlice() FieldValidator
ValidateNonEmptySlice returns a validator that ensures a slice is not empty. Works with []string, []int, []bool, and other slice types.
func ValidateNonEmptyString ¶ added in v0.7.0
func ValidateNonEmptyString() FieldValidator
ValidateNonEmptyString returns a validator that ensures a string is not empty.
func ValidatePathExists ¶ added in v0.7.0
func ValidatePathExists() FieldValidator
ValidatePathExists returns a validator that ensures a file or directory exists at the given path.
func ValidatePort ¶ added in v0.7.0
func ValidatePort() FieldValidator
ValidatePort returns a validator that ensures an int is a valid port number (1-65535).
func ValidateSliceMaxLength ¶ added in v0.7.0
func ValidateSliceMaxLength(maxLen int) FieldValidator
ValidateSliceMaxLength returns a validator that ensures a slice has at most maxLen elements.
func ValidateSliceMinLength ¶ added in v0.7.0
func ValidateSliceMinLength(minLen int) FieldValidator
ValidateSliceMinLength returns a validator that ensures a slice has at least minLen elements.
func ValidateStringMaxLength ¶ added in v0.7.0
func ValidateStringMaxLength(maxLen int) FieldValidator
ValidateStringMaxLength returns a validator that ensures a string has at most maxLen characters.
func ValidateStringMinLength ¶ added in v0.7.0
func ValidateStringMinLength(minLen int) FieldValidator
ValidateStringMinLength returns a validator that ensures a string has at least minLen characters.
func ValidateStringRegex ¶ added in v0.7.0
func ValidateStringRegex(pattern string) FieldValidator
ValidateStringRegex returns a validator that ensures a string matches the given regex pattern.
func ValidateURL ¶ added in v0.7.0
func ValidateURL() FieldValidator
ValidateURL returns a validator that ensures a string is a valid URL.
func ValidateURLWithSchemes ¶ added in v0.7.0
func ValidateURLWithSchemes(schemes ...string) FieldValidator
ValidateURLWithSchemes returns a validator that ensures a string is a valid URL with one of the allowed schemes.
type FieldValue ¶
FieldValue represents a configuration field value with its location.
type FieldValueFinder ¶
type FieldValueFinder interface {
GetFieldDependencies() map[FieldLocation]any
GetFieldValue(fieldSetKey, fieldKey string) (value any, found bool)
GetString(fieldSetKey, fieldKey string) (val string, found bool, err error)
GetStrings(fieldSetKey, fieldKey string) (val []string, found bool, err error)
GetInt(fieldSetKey, fieldKey string) (val int, found bool, err error)
GetInts(fieldSetKey, fieldKey string) (val []int, found bool, err error)
GetBool(fieldSetKey, fieldKey string) (val bool, found bool, err error)
GetBools(fieldSetKey, fieldKey string) (val []bool, found bool, err error)
GetTime(fieldSetKey, fieldKey string) (val time.Time, found bool, err error)
GetTimes(fieldSetKey, fieldKey string) (val []time.Time, found bool, err error)
GetDuration(fieldSetKey, fieldKey string) (val time.Duration, found bool, err error)
GetDurations(fieldSetKey, fieldKey string) (val []time.Duration, found bool, err error)
}
FieldValueFinder provides type-safe access to field values during load condition evaluation.
type Fields ¶
type Fields []*Field
Fields is a slice of Field elements providing context for configuration values
type FlagLoader ¶
FlagLoader loads configuration values from command-line flags.
func NewFlagLoader ¶
func NewFlagLoader() *FlagLoader
NewFlagLoader creates a new flag loader without a key prefix.
func NewFlagLoaderWithKeyPrefix ¶
func NewFlagLoaderWithKeyPrefix(keyPrefix string) *FlagLoader
NewFlagLoaderWithKeyPrefix creates a new flag loader with the specified key prefix.
func (*FlagLoader) Clone ¶
func (l *FlagLoader) Clone() *FlagLoader
Clone creates a copy of the FlagLoader.
func (*FlagLoader) CloneLoader ¶
func (l *FlagLoader) CloneLoader() Loader
CloneLoader creates a copy of the loader as a Loader interface.
func (*FlagLoader) Get ¶
func (l *FlagLoader) Get(fieldSetKey, fieldKey string) (any, bool)
Get retrieves a single field value from command-line flags.
func (*FlagLoader) GetMap ¶
func (l *FlagLoader) GetMap(fieldSetKey string, fieldKeys []string) map[string]any
GetMap retrieves multiple field values from command-line flags.
func (*FlagLoader) HelpString ¶
func (l *FlagLoader) HelpString(fieldSetKey, fieldKey string) string
HelpString returns a help string describing where this field can be configured.
type JSONFileLoader ¶
type JSONFileLoader struct {
Decoder JSONUnmarshal
FilePaths []string
// contains filtered or unexported fields
}
JSONFileLoader loads configuration values from JSON files.
func NewJSONFileLoader ¶
func NewJSONFileLoader() *JSONFileLoader
NewJSONFileLoader creates a new JSON file loader with default settings.
func NewJSONFileLoaderWithAttributes ¶
func NewJSONFileLoaderWithAttributes(decoder JSONUnmarshal, filePaths ...string) *JSONFileLoader
NewJSONFileLoaderWithAttributes creates a new JSON file loader with the specified decoder and file paths.
func (*JSONFileLoader) Clone ¶
func (l *JSONFileLoader) Clone() *JSONFileLoader
Clone creates a copy of the JSONFileLoader.
func (*JSONFileLoader) CloneLoader ¶
func (l *JSONFileLoader) CloneLoader() Loader
CloneLoader creates a copy of the loader as a Loader interface.
func (*JSONFileLoader) Get ¶
func (l *JSONFileLoader) Get(fieldSetKey, fieldKey string) (any, bool)
Get retrieves a single field value from the loaded JSON files.
func (*JSONFileLoader) GetMap ¶
func (l *JSONFileLoader) GetMap(fieldSetKey string, fieldKeys []string) map[string]any
GetMap retrieves multiple field values from the loaded JSON files.
func (*JSONFileLoader) HelpString ¶
func (l *JSONFileLoader) HelpString(fieldSetKey, fieldKey string) string
HelpString returns a help string describing where this field can be configured.
func (*JSONFileLoader) Name ¶
func (l *JSONFileLoader) Name() string
Name returns the name of this loader.
type JSONLoaderConfigOption ¶ added in v0.6.1
type JSONLoaderConfigOption interface {
ConfigOption
WithDecoder(decoder JSONUnmarshal)
}
JSONLoaderConfigOption is a configuration option for JSON file loaders that supports custom decoders.
func WithJSONFileLoader ¶
func WithJSONFileLoader(filePaths ...string) JSONLoaderConfigOption
WithJSONFileLoader enables the JSON file loader with the specified file paths.
type JSONUnmarshal ¶
JSONUnmarshal defines the function signature for JSON unmarshaling.
type LoadCondition ¶
type LoadCondition interface {
FieldValueFinder
Clone() LoadCondition
FieldDependencies() FieldLocations
SetFieldValues(fieldValues ...FieldValue)
Load(c FieldValueFinder) (bool, error)
}
LoadCondition defines conditions that control when a field should be loaded.
type LoadConditionBuilder ¶
type LoadConditionBuilder interface {
AddFieldDependencies(dependencies ...FieldLocation) LoadConditionBuilder
AddFieldSetDependencies(fieldSetKey string, fieldKeys ...string) LoadConditionBuilder
Create() LoadCondition
C() LoadCondition
}
LoadConditionBuilder provides a fluent interface for constructing LoadCondition instances.
func LCB ¶
func LCB(loadFunc func(c FieldValueFinder) (bool, error)) LoadConditionBuilder
LCB is a shorthand alias for NewLoadConditionBuilder.
func NewLoadConditionBuilder ¶
func NewLoadConditionBuilder(loadFunc func(c FieldValueFinder) (bool, error)) LoadConditionBuilder
NewLoadConditionBuilder creates a new load condition builder with the specified load function.
type LoadConditions ¶
type LoadConditions []LoadCondition
LoadConditions is a slice of LoadCondition interfaces.
type LoadOption ¶
type LoadOption interface {
LoadOptionType() string
}
LoadOption is the interface for options passed to the Load method.
func DisableGenerateFlagHandler ¶
func DisableGenerateFlagHandler() LoadOption
DisableGenerateFlagHandler returns a LoadOption that disables the built-in generate flag handler.
func DisableHelpFlagHandler ¶
func DisableHelpFlagHandler() LoadOption
DisableHelpFlagHandler returns a LoadOption that disables the built-in help flag handler.
type Loader ¶
type Loader interface {
CloneLoader() Loader
Name() string
Get(fieldSetKey, fieldKey string) (value any, found bool)
GetMap(fieldSetKey string, fieldKeys []string) (fieldValues map[string]any)
HelpString(fieldSetKey, fieldKey string) string
}
Loader is the interface that configuration loaders must implement.
type LoaderKeyOverride ¶
LoaderKeyOverride allows overriding the key used by a specific loader for a field.
type YAMLFileLoader ¶ added in v0.7.0
type YAMLFileLoader struct {
Decoder YAMLUnmarshal
FilePaths []string
// contains filtered or unexported fields
}
YAMLFileLoader loads configuration values from YAML files.
func NewYAMLFileLoader ¶ added in v0.7.0
func NewYAMLFileLoader(opts ...YAMLFileLoaderOption) *YAMLFileLoader
NewYAMLFileLoader creates a new YAML file loader with the given options. If no decoder is provided, yaml.Unmarshal from gopkg.in/yaml.v3 is used.
func (*YAMLFileLoader) Clone ¶ added in v0.7.0
func (l *YAMLFileLoader) Clone() *YAMLFileLoader
Clone creates a copy of the YAMLFileLoader.
func (*YAMLFileLoader) CloneLoader ¶ added in v0.7.0
func (l *YAMLFileLoader) CloneLoader() Loader
CloneLoader creates a copy of the loader as a Loader interface.
func (*YAMLFileLoader) Get ¶ added in v0.7.0
func (l *YAMLFileLoader) Get(fieldSetKey, fieldKey string) (any, bool)
Get retrieves a single field value from the loaded YAML files.
func (*YAMLFileLoader) GetMap ¶ added in v0.7.0
func (l *YAMLFileLoader) GetMap(fieldSetKey string, fieldKeys []string) map[string]any
GetMap retrieves multiple field values from the loaded YAML files.
func (*YAMLFileLoader) HelpString ¶ added in v0.7.0
func (l *YAMLFileLoader) HelpString(fieldSetKey, fieldKey string) string
HelpString returns a help string describing where this field can be configured.
func (*YAMLFileLoader) Name ¶ added in v0.7.0
func (l *YAMLFileLoader) Name() string
Name returns the name of this loader.
type YAMLFileLoaderOption ¶ added in v0.7.0
type YAMLFileLoaderOption func(*YAMLFileLoader)
YAMLFileLoaderOption is a functional option for configuring a YAMLFileLoader.
func WithYAMLDecoder ¶ added in v0.7.0
func WithYAMLDecoder(decoder YAMLUnmarshal) YAMLFileLoaderOption
WithYAMLDecoder sets a custom YAML decoder for the loader.
func WithYAMLFilePaths ¶ added in v0.7.0
func WithYAMLFilePaths(paths ...string) YAMLFileLoaderOption
WithYAMLFilePaths adds file paths to load configuration from.
type YAMLUnmarshal ¶ added in v0.7.0
YAMLUnmarshal defines the function signature for YAML unmarshaling.
Source Files
¶
- app_config.go
- config_options.go
- config_struct.go
- constants.go
- environment_loader.go
- field.go
- field_builder.go
- field_set.go
- field_set_builder.go
- field_set_group.go
- field_set_struct.go
- field_value_finder.go
- flag_loader.go
- json_file_loader.go
- load_condition.go
- load_condition_builder.go
- load_options.go
- loader.go
- validators.go
- yaml_file_loader.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package bconfconst provides constants used by the bconf package.
|
Package bconfconst provides constants used by the bconf package. |