Documentation
¶
Index ¶
- type Config
- func (c *Config) GetBoolOrDefault(key string, defaultValue bool) bool
- func (c *Config) GetInt(key string) int
- func (c *Config) GetIntOrDefault(key string, defaultValue int) int
- func (c *Config) GetString(key string) string
- func (c *Config) GetStringOrDefault(key string, defaultValue string) string
- func (c *Config) HasKey(key string) bool
- func (c *Config) Put(key string, value any)
- func (c *Config) ReplaceKey(key string, newKey string)
- func (c *Config) Unmarshal(v any) error
- func (c *Config) UnmarshalKey(key string, v any) error
- func (c *Config) WriteConfig() error
- type IConfig
- type SingleFileConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config wraps a Viper configuration instance and implements IConfig.
func LoadAutoConfig ¶ added in v0.1.2
func LoadAutoConfig() *Config
LoadAutoConfig creates a new empty Config, typically used when configuration is provided programmatically rather than from files.
func LoadConfig ¶
LoadConfig loads and merges multiple configuration files.
func NewConfig ¶ added in v0.1.1
func NewConfig() *Config
NewConfig creates a new empty Config with a fresh Viper instance.
func NewFromBytes ¶ added in v0.5.1
NewFromBytes creates a Config from raw bytes with the specified format (json, yaml, toml, etc.)
func (*Config) GetBoolOrDefault ¶
GetBoolOrDefault returns the bool value for the given key, or defaultValue if not set.
func (*Config) GetIntOrDefault ¶
GetIntOrDefault returns the int value for the given key, or defaultValue if not set.
func (*Config) GetStringOrDefault ¶
GetStringOrDefault returns the string value for the given key, or defaultValue if blank.
func (*Config) HasKey ¶ added in v0.1.2
HasKey reports whether the given key exists in the configuration.
func (*Config) ReplaceKey ¶ added in v0.1.2
ReplaceKey copies the value from key to newKey if key is set.
func (*Config) Unmarshal ¶ added in v0.1.1
Unmarshal unmarshals the entire configuration into the target struct. Supports both camelCase and snake_case keys in config files.
func (*Config) UnmarshalKey ¶ added in v0.1.3
UnmarshalKey unmarshals configuration under the given key into the target struct. Supports both camelCase and snake_case keys in config files.
func (*Config) WriteConfig ¶ added in v0.1.4
WriteConfig is a no-op for Config; use SingleFileConfig for file-backed writes.
type IConfig ¶ added in v0.1.2
type IConfig interface {
GetString(key string) string
Put(key string, value any)
HasKey(key string) bool
GetStringOrDefault(key string, defaultValue string) string
GetInt(key string) int
GetIntOrDefault(key string, defaultValue int) int
GetBoolOrDefault(key string, defaultValue bool) bool
Unmarshal(v any) error
UnmarshalKey(key string, v any) error
ReplaceKey(key string, newKey string)
WriteConfig() error
}
IConfig defines the interface for reading application configuration.
type SingleFileConfig ¶ added in v0.1.2
type SingleFileConfig struct {
*Config
// contains filtered or unexported fields
}
SingleFileConfig extends Config with a file path for write-back support.
func LoadSingleFileConfig ¶ added in v0.1.2
func LoadSingleFileConfig(path string) (*SingleFileConfig, error)
LoadSingleFileConfig loads a single configuration file (YAML, JSON, TOML, INI). Creates the file if it does not exist.
func (*SingleFileConfig) WriteConfig ¶ added in v0.1.2
func (c *SingleFileConfig) WriteConfig() error
WriteConfig writes the configuration back to the file.