Skip to content

moul/flexyaml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

flexyaml

CircleCI GoDoc

Flexible yaml is based on http://gopkg.in/yaml.v2 and supports case insensitive keys (!= RFC)

Used in https://github.com/moul/advanced-ssh-config

Example

package main

import (
    "fmt"
    "log"

    "github.com/moul/flexyaml"
)

// An example showing how to unmarshal embedded
// structs from YAML.

type StructA struct {
    A string `yaml:"a"`
}

type StructB struct {
    // Embedded structs are not treated as embedded in YAML by default. To do that,
    // add the ",inline" annotation below
    StructA `yaml:",inline"`
    B       string `yaml:"b"`
}

var data = `
a: a string from struct A
B: a string from struct B
`

func main() {
    var b StructB

    err := flexyaml.Unmarshal([]byte(data), &b)
    if err != nil {
        log.Fatal("cannot unmarshal data: %v", err)
    }
    fmt.Println(b.A)
    fmt.Println(b.B)
}

License

MIT