go-yaml / yaml

YAML support for the Go language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG]: Aliases does not unmarshal (mapping key "<<" already defined ...)

zombieleet opened this issue · comments

I am currently using the v3 of go-yaml , the problem is that unmarshalling multiple alias throws mapping key "<<" already defined at line 10. Below is the example code and yaml file

package main

import (
	"fmt"
	"log"
	"os"

	"gopkg.in/yaml.v3"
)

type Foo struct {
	Foo map[string]interface{} `yaml:"foo"`
}

func main() {

	file, err := os.Open("./test.yaml")

	if err != nil {
		log.Fatal(err)
	}

	x, _ := file.Stat()

	content := make([]byte, x.Size())

	_, err = file.Read(content)

	if err != nil {
		log.Fatal(err)
	}

	c := Foo{}

	err = yaml.Unmarshal(content, &c)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(c)
}
reuse:
  - &reuse
    bar: "baz"

reuse2:
  - &reuse2
    baz: "foobar"

foo:
  <<: *reuse
  <<: *reuse2