-
-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Parsing YAML files with anchors does not keep pointers to anchors when unmarshalling #71
Comments
I just tested this with the above code, and it does not work. The |
The above code is wrong, it does not work . The following code works fine . package main
import (
"github.com/goccy/go-yaml"
)
type Host struct {
Hostname string
Username string
Password string
}
type HostList struct {
Host *Host `yaml:",anchor"`
}
type Queue struct {
Name string `yaml:","`
*Host `yaml:",alias"`
}
type ConfigFile struct {
HostList []*HostList `yaml:"hosts"`
Queues []*Queue `yaml:"queues"`
}
func main() {
yml := `
hosts:
- host: &host1
hostname: queue.example.com
username: queue1
password: queue1
port: 5672
- host: &host2
hostname: queue2.example.com
username: queue2
password: queue2
port: 5672
queues:
- name: queue
host: *host1
- name: queue2
host: *host1
- name: queue3
host: *host2
`
var cf ConfigFile
if err := yaml.Unmarshal([]byte(yml), &cf); err != nil {
panic(err)
}
cf.Queues[0].Host.Hostname = "updated"
} |
Ah! It happened when Thanks so much for all your help here @goccy I will try over the next couple of days to get Words can't explain how much I appreciate the last two commits :) |
Thanks @goccy for your work on this package :)
Similar to #69, I have a configuration file that looks like this:
I have a set of structs in a separate package, describing the YAML file
I am reading my configuration file like this
and inside my
main.go
, I have the following code:Expected output:
Actual output:
It seems that the anchor in the created document to
host1
is not being respected when unmarshalling the document.I would expect that both
Configuration.Queues[0].Host
andConfiguration.Queues[1].Host
would be a pointer toConfiguration.Hosts[0].Host
, reflecting the document's intent.The text was updated successfully, but these errors were encountered: