go-yaml
go-yaml copied to clipboard
Unmarshal() fails with an error "duplicated struct field name"
Version
v1.10.0
Description
When there is a field with a name that matches the custom key of a tag attached to another field in the structure, Unmarshal() fails with an error "duplicated struct field name".
構造体の別のフィールドに付けられたタグのカスタムキーと一致する名前のフィールドがある場合に「重複したフィールド名」としてUnmarshal()が失敗する。
How to reproduce
Test code
package main
import (
"github.com/goccy/go-yaml"
"log"
)
type Config struct {
Domain string
Host string `yaml:"domain"`
}
func main() {
config := Config{}
buf := "---\ndomain:\n"
if err := yaml.Unmarshal([]byte(buf), &config); err != nil {
log.Fatal(err)
}
}
Result
2023/03/06 17:23:25 duplicated struct field name domain:
github.com/goccy/go-yaml.structFieldMap
/home/user/go/pkg/mod/github.com/goccy/[email protected]/struct.go:124