Documentation
¶
Index ¶
- func GetConfigData(cfgPath string, workDir string, envSpecMap ...EnvSpecMap) (_ []byte, gErr error)
- func GetConfigDir() string
- func GetConfigPath() string
- func LoadMergedConfigData(cfgPath string) (_ []byte, gErr error)
- func LoadMergedData() []byte
- func Merge[A any, B any | *any](dst *A, src ...B) error
- func MergeR[A any, B any | *any](dst *A, src ...B) (r result.Result[*A])
- func RegisterExpr(name string, fn any) error
- func SetConfigPath(confPath string)
- func TryLoadMergedData() ([]byte, error)
- func ValidateEnvReferences(cfgPath string) (gErr error)
- type Base64File
- type Cfg
- type EnvSpec
- type EnvSpecMap
- type ExprExistsError
- type ListOrMap
- type Manager
- func (m *Manager) GetConfigData() any
- func (m *Manager) GetDir() string
- func (m *Manager) GetEnvMap() EnvSpecMap
- func (m *Manager) GetExprFns() map[string]any
- func (m *Manager) GetPath() string
- func (m *Manager) RegisterExprFunc(name string, fn any) error
- func (m *Manager) SetConfigData(data any)
- func (m *Manager) SetDir(dir string)
- func (m *Manager) SetEnvMap(data EnvSpecMap)
- func (m *Manager) SetPath(path string)
- type NamedConfig
- type Node
- type Resources
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetConfigData ¶
func GetConfigData(cfgPath string, workDir string, envSpecMap ...EnvSpecMap) (_ []byte, gErr error)
GetConfigData loads and processes config file content with optional envSpecMap validation. If envSpecMap is provided, env() calls in the config will be validated against defined vars. workDir is the root config directory used for embed() path resolution.
func GetConfigDir ¶
func GetConfigDir() string
func GetConfigPath ¶
func GetConfigPath() string
func LoadMergedConfigData ¶
LoadMergedConfigData returns the fully merged, processed config content in YAML format.
Processing includes:
- env initialization from patch_envs
- template/CEL evaluation for each config file
- merge order: main config -> resources -> patch_resources
Meta fields (resources/patch_resources/patch_envs) are removed from returned content.
func LoadMergedData ¶
func LoadMergedData() []byte
LoadMergedData loads fully merged, processed config data (panics on error). For better error handling, use TryLoadMergedData instead.
func RegisterExpr ¶
RegisterExpr registers a custom expression function for use in config templates. Returns error if the name already exists. For backward compatibility, use MustRegisterExpr for panic behavior. Note: Custom functions must have simple signatures: func() T or func(T) R
func SetConfigPath ¶
func SetConfigPath(confPath string)
func TryLoadMergedData ¶
TryLoadMergedData attempts to load fully merged, processed config data and returns error instead of panicking.
It resolves config path in the same way as TryLoad:
- use global configured path if set
- otherwise auto-discover by default config name/type
func ValidateEnvReferences ¶
ValidateEnvReferences validates that env vars used in config files are declared in patch_envs.
It checks env references in:
- main config file
- resources files
- patch_resources files
This method is intended for explicit/manual validation. Normal loading no longer forces env reference declaration checks during parsing.
Types ¶
type Base64File ¶
type Base64File string
func (*Base64File) MarshalYAML ¶
func (b *Base64File) MarshalYAML() (any, error)
func (*Base64File) UnmarshalYAML ¶
func (b *Base64File) UnmarshalYAML(value *yaml.Node) error
type Cfg ¶
type Cfg[T any] struct { T T P *T EnvCfg *EnvSpecMap }
type EnvSpec ¶
type EnvSpec struct {
// Name of the environment variable.
Name string `yaml:"name"`
Desc string `yaml:"desc"`
Default string `yaml:"default"`
Value string `yaml:"value"`
Example string `yaml:"example"`
// Validation using go-playground/validator tags
// Examples: "required", "email", "url", "uuid", "ip", "numeric", "min=3,max=50"
Rule string `yaml:"validate"`
}
type EnvSpecMap ¶
func LoadEnvMap ¶
func LoadEnvMap(cfgPath string) EnvSpecMap
func (EnvSpecMap) ValidateAll ¶
func (m EnvSpecMap) ValidateAll() error
ValidateAll validates all environment specs in the map
type ExprExistsError ¶
type ExprExistsError struct {
Name string
}
ExprExistsError is returned when trying to register a duplicate expression
func (*ExprExistsError) Error ¶
func (e *ExprExistsError) Error() string
type ListOrMap ¶
type ListOrMap[T any] []T
func (*ListOrMap[T]) MarshalYAML ¶
MarshalYAML implements the yaml.Marshaler interface.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager provides thread-safe configuration management
func (*Manager) GetConfigData ¶
func (*Manager) GetEnvMap ¶
func (m *Manager) GetEnvMap() EnvSpecMap
func (*Manager) GetExprFns ¶
GetExprFns returns a copy of registered expression functions
func (*Manager) RegisterExprFunc ¶
RegisterExprFunc registers a custom expression function in a thread-safe manner
func (*Manager) SetConfigData ¶
func (*Manager) SetEnvMap ¶
func (m *Manager) SetEnvMap(data EnvSpecMap)
type NamedConfig ¶
type NamedConfig interface {
// ConfigUniqueName unique name
ConfigUniqueName() string
}
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
func (*Node) MarshalJSON ¶
func (*Node) MarshalYAML ¶
type Resources ¶
type Resources struct {
// Resources resource config file or dir must exist
Resources []string `yaml:"resources"`
// PatchResources resource config file or dir not required to exist
PatchResources []string `yaml:"patch_resources"`
// PatchEnvs env config file or dir not required to exist
PatchEnvs []string `yaml:"patch_envs"`
}