【发布时间】:2019-05-23 15:05:16
【问题描述】:
我正在使用structs 库轻松地遍历结构的字段,例如:
package main
import "github.com/fatih/structs"
type T struct {
}
func main() {
s := structs.New(T{})
for _, field := range s.Fields() {
switch field.Kind() {
case bool:
// do something
case string:
// do something
}
}
}
目前上面的代码不起作用,因为 field.Kind 是一个 reflect.Type。有没有可能让它以某种方式工作?
谢谢。
【问题讨论】: