我正在尝试在 Go 中解析一些 xml 文档。为此,我需要定义一些结构,而我的结构标签取决于特定条件。
想象一下下面的代码(即使我知道它不会工作)
if someCondition {
type MyType struct {
// some common fields
Date []string `xml:"value"`
}
} else {
type MyType struct {
// some common fields
Date []string `xml:"anotherValue"`
}
}
var t MyType
// do the unmarshalling ...
问题是这两个结构有很多共同的字段。唯一的区别在于其中一个字段,我想防止重复。我怎么解决这个问题?
慕码人8056858
神不在的星期二
慕尼黑8549860
相关分类