我定义了一个user model:
type User struct {
Id uint `model:"id"`
Username string `model:"username"`
MobileNo string `model:"mobile_no"`
Password string `model:"password"`
Email string `model:"email"`
EmailVerified uint8 `model:"email_verified"`
CreateTime string `model:"create_time"`
UpdateTime string `model:"uptime_time"`
}
func (user *User) TableName() string {
return "user"
}
这个user model有实现一个baseModel接口。
然后我查询数据:
user := &model.User{}
db.BuildCommand(user).FindOne()
BuildCommand:
type Command struct {
model BaseModel
sql string //最终的SQL语句
selt string //sql 的select
from string
where string
limit int
offset int
}
var c *Command
func BuildCommand(m BaseModel) *Command {
if c == nil {
c = &Command{
model: m,
}
} else {
c.model = m
}
return c
}
然后我在把查询出来的数据写到user model里面的时候,反射user model结构报错了。 panic serving [::1]:50250: reflect: NumField of non-struct type
//....
//这里的q就是上门的*Command
refValue := reflect.ValueOf(q.model)
refType := refValue.Type()
//....
//就下面这一行报错的。
log.Fatalln(refType.NumField())
//.....
这是怎么回事?