遍历map列表的Golang模板

遍历map列表的Golang模板遇到的问题及解决方式 出现了什么问题? 今天在使用 go template 渲染文本的时候,在运行的时候,遇到了一个问题导致渲染不成功,具体的问题是: 1 2021/09/10 09:47:05 template: test:2:3: executing "test" at <.Attributes>: can't evaluate field Attributes in type interface {} 具体的代码如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 package main import ( "log" "os" "strings" "text/template" ) type TestData struct { Name string `json:"name"` Attributes map[string]interface{} } const testTemplate = `{{ range $key, $value := ....

September 10, 2021 · 2 min · overstarry