【发布时间】:2016-01-26 05:25:03
【问题描述】:
将结构转储到提供的 csv 文件中的惯用 golang 方法是什么?我在一个 func 中,我的结构作为 interface{} 传递:
func decode_and_csv(my_response *http.Response, my_struct interface{})
为什么是接口{}? - 从 JSON 读取数据,可能会返回几个不同的结构,因此尝试编写足够通用的函数。
我的类型示例:
type Location []struct {
Name string `json: "Name"`
Region string `json: "Region"`
Type string `json: "Type"`
}
【问题讨论】: