【发布时间】:2015-06-12 00:45:09
【问题描述】:
我正在阅读an article on golang templates,这出现在示例代码中。
func renderTemplate(w http.ResponseWriter, name string, data map[string]interface{}) error {
// Ensure the template exists in the map.
tmpl, ok := templates[name]
if !ok {
return fmt.Errorf("The template %s does not exist.", name)
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
tmpl.ExecuteTemplate(w, "base", data)
return nil
}
我不明白的部分是函数声明中的参数data:
data map[string]interface{}
我对go中的接口只有非常基本的了解,但不知道为什么会这样使用。
【问题讨论】:
标签: go