提问人:404 提问时间:3/5/2023 更新时间:3/5/2023 访问量:60
基于 Yaml 的 Go 结构选择器
Yaml Based Selector For Go Structures
问:
对于具有从 yaml 取消封组的定义的结构
type Complex struct {
Im float `yaml:"im"`
Re float `yaml:"re"`
}
type A struct {
Property int `yaml:"prop"`
Items []*Complex `yaml:"items"`
}
type B struct {
Nested *A `yaml:"sub"`
}
有没有办法从实例化的变量中解析值,例如
var b B = initiateWhatever()
基于 YAML 空间的路径(而不是 Go 属性名称)
targetValue := resolve(b, "sub.prop")
或者,甚至可能有任何工具可以进行复杂的选择,就像 json 或 yaml 一样。但这个想法仍然是操作的不是序列化数据,而是实例化结构,它自己jq
yq
itemReals := resolve(b, "sub.items[*].re") // array of floats desired here
答: 暂无答案
下一个:用于流式处理的 GRPC 元
评论
struct
yaml.Node