Documentation
¶
Overview ¶
Package config provides configuration loading and management utilities with file and env backends.
Index ¶
- Variables
- func FieldsChangedByTag(old, new interface{}, tag string, triggers map[string]bool) []string
- func MergeOverlayBytes(dst interface{}, overlay []byte) error
- func NormalizeTLSPaths(tls *models.TLSConfig, certDir string)
- func SanitizeTOML(data []byte, deny []TOMLPath) []byte
- func TemplateStorageKey(desc ServiceDescriptor) string
- func ValidateConfig(cfg interface{}) error
- type Config
- type ConfigFormat
- type ConfigLoader
- type ConfigScope
- type EnvConfigLoader
- type FileConfigLoader
- type KeyContext
- type ServiceDescriptor
- type TOMLPath
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDstMustBeNonNilPointer indicates that the destination must be a non-nil pointer. ErrDstMustBeNonNilPointer = errors.New("dst must be a non-nil pointer") // ErrDstMustBePointerToStruct indicates that the destination must be a pointer to a struct. ErrDstMustBePointerToStruct = errors.New("dst must be a pointer to a struct") )
Functions ¶
func FieldsChangedByTag ¶ added in v1.0.55
FieldsChangedByTag returns a list of struct field names whose tag matches any value in triggers and whose values differ between old and new. Only compares top-level exported fields.
func MergeOverlayBytes ¶ added in v1.0.55
MergeOverlayBytes deep-merges a JSON document onto an existing config struct in memory. Fields present in overlay override destination; others remain unchanged.
func NormalizeTLSPaths ¶
NormalizeTLSPaths is a convenience function that normalizes TLS paths with default logging. This function exists for backward compatibility with existing code.
func SanitizeTOML ¶ added in v1.0.55
SanitizeTOML drops lines containing sensitive keys from a TOML document without needing a full parser. It handles basic table headers ([table]) and key/value pairs (key = value). Multiline strings or inline tables are preserved unless the first line contains a denied key.
func TemplateStorageKey ¶ added in v1.0.55
func TemplateStorageKey(desc ServiceDescriptor) string
TemplateStorageKey returns the canonical KV location for storing a descriptor's default template.
func ValidateConfig ¶
func ValidateConfig(cfg interface{}) error
ValidateConfig validates a configuration if it implements Validator.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config holds the configuration loading dependencies.
func NewConfig ¶
NewConfig initializes a new Config instance with a default file loader and logger. If logger is nil, creates a basic logger for config loading.
func (*Config) LoadAndValidate ¶
LoadAndValidate loads a configuration, normalizes SecurityConfig paths if present, and validates it.
func (*Config) OverlayPinned ¶ added in v1.0.55
OverlayPinned applies a pinned configuration file on top of the existing config. Fields present in the pinned file take precedence over both defaults and KV overlays.
type ConfigFormat ¶ added in v1.0.55
type ConfigFormat string
ConfigFormat identifies how a service persists its configuration.
const ( ConfigFormatJSON ConfigFormat = "json" ConfigFormatTOML ConfigFormat = "toml" )
func TemplateStorageKeyFor ¶ added in v1.0.55
func TemplateStorageKeyFor(name string) (string, ConfigFormat, bool)
TemplateStorageKeyFor returns the template storage key for the provided descriptor name, if known.
type ConfigLoader ¶
Loader interface for loading configurations from various sources.
type ConfigScope ¶ added in v1.0.55
type ConfigScope string
ConfigScope describes how a service scopes its configuration.
const ( ConfigScopeGlobal ConfigScope = "global" ConfigScopeGateway ConfigScope = "gateway" ConfigScopeAgent ConfigScope = "agent" )
type EnvConfigLoader ¶ added in v1.0.55
type EnvConfigLoader struct {
// contains filtered or unexported fields
}
EnvConfigLoader loads configuration from environment variables. It supports nested struct fields using underscore separation (e.g., CNPG_HOST maps to config.cnpg.host).
func NewEnvConfigLoader ¶ added in v1.0.55
func NewEnvConfigLoader(log logger.Logger, prefix string) *EnvConfigLoader
NewEnvConfigLoader creates a new environment variable config loader.
type FileConfigLoader ¶
type FileConfigLoader struct {
// contains filtered or unexported fields
}
FileConfigLoader loads configuration from a local JSON file.
type KeyContext ¶ added in v1.0.55
KeyContext supplies identity information used to resolve scoped KV keys.
type ServiceDescriptor ¶ added in v1.0.55
type ServiceDescriptor struct {
Name string
DisplayName string
ServiceType string
Scope ConfigScope
KVKey string
KVKeyTemplate string
Format ConfigFormat
CriticalFields []string
}
ServiceDescriptor captures metadata about a managed service configuration.
func ServiceDescriptorByType ¶ added in v1.0.55
func ServiceDescriptorByType(serviceType string, scope ConfigScope) (ServiceDescriptor, bool)
ServiceDescriptorByType returns the descriptor matching a service type within the provided scope.
func ServiceDescriptorFor ¶ added in v1.0.55
func ServiceDescriptorFor(name string) (ServiceDescriptor, bool)
ServiceDescriptorFor returns the descriptor for a named service if it exists.
func ServiceDescriptors ¶ added in v1.0.55
func ServiceDescriptors() []ServiceDescriptor
ServiceDescriptors returns the known service descriptors in deterministic order.
func (ServiceDescriptor) ResolveKVKey ¶ added in v1.0.55
func (sd ServiceDescriptor) ResolveKVKey(ctx KeyContext) (string, error)
ResolveKVKey returns the KV key for the descriptor within the provided context.