Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Parse ¶
Parse takes the given path and attempts to read and unmarshal the config The given config will also be validated if it has a Validate function on it
Example ¶
package main import ( "log/slog" "github.com/aranw/yamlcfg" ) type Config struct { LogLevel string `yaml:"log_level"` } func main() { cfg, err := yamlcfg.Parse[Config]("config.yaml") if err != nil { slog.Error("loading yaml config", "err", err) return } _ = cfg.LogLevel }
Output:
func ParseFS ¶
ParseFS attempts to load the given path and config from a embed.FS
Example ¶
package main import ( "embed" "log/slog" "github.com/aranw/yamlcfg" ) type Config struct { LogLevel string `yaml:"log_level"` } //go:embed testdata var testdata embed.FS func main() { cfg, err := yamlcfg.ParseFS[Config](testdata, "config.yaml") if err != nil { slog.Error("loading yaml config", "err", err) return } _ = cfg.LogLevel }
Output:
func UnmarshalConfig ¶
UnmarshalConfig takes the provided yaml data and unmarshals it into the provided config struct. It will return an error if the decoding fails or if the yaml data is not in the expected format. It will also expand any environment variables in the yaml data
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.