config

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllRegisteredKeys

func AllRegisteredKeys() []string

AllRegisteredKeys returns all registered config keys sorted alphabetically.

func DefaultConfigs

func DefaultConfigs() map[string]interface{}

DefaultConfigs returns a map of all registered config keys with their default values. Only keys that have a non-nil Default value are included.

func EnsureDefaultsLoaded

func EnsureDefaultsLoaded(k *koanf.Koanf)

EnsureDefaultsLoaded loads config defaults if not already loaded. Only sets default values for keys that don't already exist in the config.

This should be called after all plugins have registered their config keys (typically in the server builder, after all init() functions have run). Thread-safe - uses sync.Once to ensure defaults are loaded exactly once.

func FindSimilarKeys

func FindSimilarKeys(key string, maxResults int) []string

FindSimilarKeys finds registered keys that are similar to the given key. Returns up to maxResults keys sorted by similarity (most similar first).

Uses a combination of: - Levenshtein distance for typo detection - Prefix matching for hierarchical keys

With moderate thresholds: - Edit distance ≤ 3 for general matching - Edit distance ≤ 2 for keys with matching prefixes

func FormatValidationWarnings

func FormatValidationWarnings(warnings []ValidationWarning) string

FormatValidationWarnings formats a slice of validation warnings into a readable message.

func HasRegisteredPrefix

func HasRegisteredPrefix(key string) bool

HasRegisteredPrefix checks if any registered key starts with the given prefix. Used to allow unknown keys under registered namespaces (e.g., "myapp.*").

func IsRegisteredKey

func IsRegisteredKey(key string) bool

IsRegisteredKey checks if a config key is known in the registry.

func RegisterConfigKey

func RegisterConfigKey(info ConfigKeyInfo)

RegisterConfigKey registers a known configuration key with metadata. This should be called by core code and plugins to document expected config keys.

func RegisterConfigKeys

func RegisterConfigKeys(infos ...ConfigKeyInfo)

RegisterConfigKeys registers multiple configuration keys at once.

func RegisterDeprecatedKey

func RegisterDeprecatedKey(oldKey, newKey string)

RegisterDeprecatedKey registers a deprecated configuration key and its replacement.

func SearchForConfig

func SearchForConfig(filename string, startDir string) string

SearchForConfig recursively searches for a config file starting from startDir and walking up the directory tree until found or reaching the root.

func TransformEnv

func TransformEnv(s string) string

TransformEnv converts PF__SERVER__INCOMING_HEADERS to server.incomingHeaders. Environment variable transformation rules:

  • Remove PF__ prefix
  • Convert to lowercase
  • Double underscores (__) become dots (.)
  • Single underscores (_) within segments become camelCase

Types

type ConfigKeyInfo

type ConfigKeyInfo struct {
	Key         string      // The full config key path (e.g., "server.port")
	Description string      // Human-readable description of what this config does
	Type        string      // Type hint: "string", "int", "bool", "duration", "[]string", etc.
	Default     interface{} // Optional default value
	Deprecated  bool        // If true, this key is deprecated
	ReplacedBy  string      // If deprecated, the new key to use instead
}

ConfigKeyInfo contains metadata about a known configuration key.

func LookupConfigKey

func LookupConfigKey(key string) (ConfigKeyInfo, bool)

LookupConfigKey returns metadata for a registered config key.

type ValidationWarning

type ValidationWarning struct {
	Key         string
	Suggestions []string
}

ValidationWarning represents a configuration warning for unknown or potentially misspelled keys.

func ValidateConfigKeys

func ValidateConfigKeys(config *koanf.Koanf) []ValidationWarning

ValidateConfigKeys checks all loaded configuration keys against the registry and returns warnings for unknown keys with suggestions for similar keys.

This validation uses Config.Keys() to enumerate all loaded keys from all sources (YAML files, environment variables, defaults, etc.) and compares them against the registered known keys.

func (ValidationWarning) String

func (w ValidationWarning) String() string

Jump to

Keyboard shortcuts

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