yaml

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package yaml is a driver use YAML format content as config source

Usage please see example:

Example
config.WithOptions(config.ParseEnv)

// add yaml decoder
// only add decoder
// config.SetDecoder(config.Yaml, Decoder)
// Or
config.AddDriver(Driver)

err := config.LoadFiles("../testdata/yml_other.yml")
if err != nil {
	panic(err)
}

// load from string
_ = config.LoadSources(config.Yaml, []byte(yamlStr))

fmt.Print("get config example:\n")

name := config.String("name")
fmt.Printf("get string\n - val: %v\n", name)

arr1 := config.Strings("arr1")
fmt.Printf("get array\n - val: %#v\n", arr1)

val0 := config.String("arr1.0")
fmt.Printf("get sub-value by path 'arr.index'\n - val: %#v\n", val0)

map1 := config.StringMap("map1")
fmt.Printf("get map\n - val: %#v\n", map1)

val0 = config.String("map1.key")
fmt.Printf("get sub-value by path 'map.key'\n - val: %#v\n", val0)

// can parse env name(ParseEnv: true)
fmt.Printf("get env 'envKey' val: %s\n", config.String("envKey", ""))
fmt.Printf("get env 'envKey1' val: %s\n", config.String("envKey1", ""))

// Out:
// get config example:
// age: 23
// get string
// - val: app2
// get array
// - val: []string{"val1", "val21"}
// get sub-value by path 'arr.index'
// - val: "val1"
// get map
// val: map[string]string{"key":"val2", "key2":"val20"}
// get sub-value by path 'map.key'
// - val: "val2"
// get env 'envKey' val: /bin/zsh
// get env 'envKey1' val: defValue

Index

Examples

Constants

This section is empty.

Variables

Decoder the yaml content decoder

Driver for yaml

Encoder the yaml content encoder

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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