config

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

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

func LoadConfig(paths ...string) (*Config, error)

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

func NewFromBytes(data []byte, format string) (*Config, error)

NewFromBytes creates a Config from raw bytes with the specified format (json, yaml, toml, etc.)

func (*Config) GetBoolOrDefault

func (c *Config) GetBoolOrDefault(key string, defaultValue bool) bool

GetBoolOrDefault returns the bool value for the given key, or defaultValue if not set.

func (*Config) GetInt

func (c *Config) GetInt(key string) int

GetInt returns the int value for the given key.

func (*Config) GetIntOrDefault

func (c *Config) GetIntOrDefault(key string, defaultValue int) int

GetIntOrDefault returns the int value for the given key, or defaultValue if not set.

func (*Config) GetString

func (c *Config) GetString(key string) string

GetString returns the string value for the given key.

func (*Config) GetStringOrDefault

func (c *Config) GetStringOrDefault(key string, defaultValue string) string

GetStringOrDefault returns the string value for the given key, or defaultValue if blank.

func (*Config) HasKey added in v0.1.2

func (c *Config) HasKey(key string) bool

HasKey reports whether the given key exists in the configuration.

func (*Config) Put added in v0.1.2

func (c *Config) Put(key string, value any)

Put sets a configuration value.

func (*Config) ReplaceKey added in v0.1.2

func (c *Config) ReplaceKey(key string, newKey string)

ReplaceKey copies the value from key to newKey if key is set.

func (*Config) Unmarshal added in v0.1.1

func (c *Config) Unmarshal(v any) error

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

func (c *Config) UnmarshalKey(key string, v any) error

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

func (c *Config) WriteConfig() error

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.

Jump to

Keyboard shortcuts

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