【发布时间】:2016-11-18 20:41:40
【问题描述】:
假设我们有以下 go 代码
type SectionType int
const (
Header SectionType = iota
Footer
Body
)
var sectionTypeNames = map[string]SectionType{
"header": Header
"footer": Footer
"body": Body
}
type Page struct {
Sections: []SectionType `yaml:"sections"`
}
我们有以下yaml
page1:
- header
- body
有没有办法让 goyaml 将“header”和“body”的字符串转换为它们各自的 int 常量类型(定义在 sectionTypeNames 映射中)我们反序列化 Page 结构?
【问题讨论】: