Last active
March 27, 2019 13:45
-
-
Save rgarcia/0986f045d870fc09a65adbde29ee6ff2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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