【发布时间】:2016-03-12 20:02:45
【问题描述】:
我正在尝试学习 goyaml,但在尝试从 yaml 生成切片时遇到了一些问题。我可以将我的结构编组到这个示例 yaml 中,但我不能将相同的 yaml 解组回结构中。
input:
file:
- file: stdin
webservice:
- port: "0000"
address: 0.0.0.0
processing:
regex:
- regex: ^(this)*
mapping: (1) thing
output:
file:
- file: stdout
webservice:
- port: "0000"
address: 0.0.0.0
结构:
type Configuration struct{
Input ioInstance
Processing ProcessingInstance
Output ioInstance
}
type ioInstance struct {
File []FileInstance
Webservice []WebserviceInstance
}
type FileInstance struct {
File string
}
type WebserviceInstance struct {
Port string
Address string
}
type ProcessingInstance struct {
Regex []RegexInstance
}
type RegexInstance struct {
Regex string
Mapping string
}
在测试解组时,我遇到了反射错误,据我了解,我认为我可能需要在没有结构切片的情况下重新设计,我希望有人可以对此提供一些见解?
错误:
panic: reflect: reflect.Value.Set using unaddressable value [recovered]
panic: reflect: reflect.Value.Set using unaddressable value [recovered]
panic: reflect: reflect.Value.Set using unaddressable value
【问题讨论】:
-
您使用的是最新的软件包吗? “github.com/go-yaml/yaml”已移至“gopkg.in/yaml.v2”