Skip to content

Instantly share code, notes, and snippets.

@rgarcia
Last active March 27, 2019 13:45
Show Gist options
  • Save rgarcia/0986f045d870fc09a65adbde29ee6ff2 to your computer and use it in GitHub Desktop.
Save rgarcia/0986f045d870fc09a65adbde29ee6ff2 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"gopkg.in/yaml.v2"
)
const withAlias = `foo:
<<: &integer
type: integer
format: int16
bar:
<<: *integer
`
func main() {
var ms yaml.MapSlice
if err := yaml.Unmarshal([]byte(withAlias), &ms); err != nil {
log.Fatal(err)
}
fmt.Println(pretty(ms))
fmt.Println("----")
var i interface{}
if err := yaml.Unmarshal([]byte(withAlias), &i); err != nil {
log.Fatal(err)
}
fmt.Println(pretty(i))
}
func pretty(i interface{}) string {
bs, _ := yaml.Marshal(i)
return string(bs)
}
foo: {}
bar: {}
----
bar:
format: int16
type: integer
foo:
format: int16
type: integer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment