cfg

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadDotEnv

func LoadDotEnv(path string) error

LoadDotEnv parses the .env file at path and exports its KEY=VALUE pairs into the process environment (KWL-Q7X4M KWL-DOTV-001). Variables already present in the process environment are never overwritten, so real environment wins over .env. A missing file is not an error.

func ParseDotEnv

func ParseDotEnv(data []byte) ([]dotenvPair, error)

ParseDotEnv parses .env file content into ordered KEY=VALUE pairs. Blank lines and # comments are skipped; an optional "export " prefix is accepted; values may be wrapped in single or double quotes (KWL-Q7X4M KWL-DOTV-002).

Types

type Config

type Config map[string]string

Config represents the key-value configuration store. It's a simple string-to-string map that can be loaded from and saved to YAML files.

func Load

func Load(path string) (Config, error)

Load reads a YAML file and returns a Config map. If the file doesn't exist, it returns an empty Config (not an error).

func (Config) Delete

func (c Config) Delete(key string)

Delete removes a key.

func (Config) EnvOverride

func (c Config) EnvOverride(prefix string) Config

EnvOverride applies environment variables with the given prefix. Environment variables are converted to lower-case keys with dots. e.g., APP_SERVER_PORT=8080 -> server.port

func (Config) Get

func (c Config) Get(key string) string

Get returns the value for key, or empty string if not found.

func (Config) GetOr

func (c Config) GetOr(key, fallback string) string

GetOr returns the value for key, or fallback when the key is absent. It is the lookup primitive for config getters that read environment variables with in-code defaults (KWN-Q7X4M).

func (Config) Keys

func (c Config) Keys() []string

Keys returns all keys in sorted order.

func (Config) Merge

func (c Config) Merge(other Config) Config

Merge merges another Config into this one, with other taking precedence.

func (Config) Save

func (c Config) Save(path string) error

Save writes the Config map to a YAML file.

func (Config) Set

func (c Config) Set(key, value string)

Set sets a key-value pair.

func (Config) WithDefaults

func (c Config) WithDefaults(defaults Config) Config

Defaults returns a new Config with default values applied (non-destructive).

Jump to

Keyboard shortcuts

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