config

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package config provides configuration loading and management utilities with file and env backends.

Index

Constants

This section is empty.

Variables

View Source
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

func FieldsChangedByTag(old, new interface{}, tag string, triggers map[string]bool) []string

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

func MergeOverlayBytes(dst interface{}, overlay []byte) error

MergeOverlayBytes deep-merges a JSON document onto an existing config struct in memory. Fields present in overlay override destination; others remain unchanged.

func NormalizeTLSPaths

func NormalizeTLSPaths(tls *models.TLSConfig, certDir string)

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

func SanitizeTOML(data []byte, deny []TOMLPath) []byte

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

func NewConfig(log logger.Logger) *Config

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

func (c *Config) LoadAndValidate(ctx context.Context, path string, cfg interface{}) error

LoadAndValidate loads a configuration, normalizes SecurityConfig paths if present, and validates it.

func (*Config) OverlayPinned added in v1.0.55

func (c *Config) OverlayPinned(ctx context.Context, pinnedPath string, cfg interface{}) error

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

type ConfigLoader interface {
	Load(ctx context.Context, path string, dst interface{}) error
}

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.

func (*EnvConfigLoader) Load added in v1.0.55

func (e *EnvConfigLoader) Load(_ context.Context, _ string, dst interface{}) error

Load implements ConfigLoader by reading from environment variables.

type FileConfigLoader

type FileConfigLoader struct {
	// contains filtered or unexported fields
}

FileConfigLoader loads configuration from a local JSON file.

func (*FileConfigLoader) Load

func (f *FileConfigLoader) Load(_ context.Context, path string, dst interface{}) error

Load implements ConfigLoader by reading and unmarshaling a JSON file.

type KeyContext added in v1.0.55

type KeyContext struct {
	AgentID   string
	GatewayID string
}

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.

type TOMLPath added in v1.0.55

type TOMLPath struct {
	Table string
	Key   string
}

TOMLPath identifies a specific key inside an optional table (e.g. table="outputs.prometheus", key="token"). Use Table="*" to match keys in any table or Key="*" to drop an entire table.

type Validator

type Validator interface {
	Validate() error
}

Validator interface for configurations that need validation.

Directories

Path Synopsis
Package kv provides interfaces for key-value store configuration management.
Package kv provides interfaces for key-value store configuration management.

Jump to

Keyboard shortcuts

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