我很难在 Go 中解组这段 YAML。我得到的错误是cannot unmarshal !!seq into map[string][]map[string][]string。我尝试了所有类型的地图都没有成功(map[string]string ; []map[string]string 等等)import ( "gopkg.in/yaml.v1" "io/ioutil")type AppYAML struct { Runtime string `yaml:"runtime,omitempty"` Handlers map[string][]map[string][]string `yaml:"handlers,omitempty"` Env_Variables map[string]string `yaml:"env_variables,omitempty"`}func main() { s := `runtime: gohandlers:- url: /.* runtime: _go_app secure: alwaysenv_variables: something: 'test'` var a AppYAML if err = yaml.Unmarshal([]byte(s), &a); err != nil { log.Error(err) return }}
1 回答
qq_笑_17
TA贡献1818条经验 获得超7个赞
将类型声明更改为:
type AppYAML struct {
Runtime string `yaml:"runtime,omitempty"`
Handlers []map[string]string `yaml:"handlers,omitempty"`
Env_Variables map[string]string `yaml:"env_variables,omitempty"`
}
- 1 回答
- 0 关注
- 279 浏览
添加回答
举报
0/150
提交
取消