struct中存在未导出的字段时,CreateTableIfNotExists 提示反射错误。
tioncai opened this issue · 5 comments
tioncai commented
我定义的struct如下:
type Card struct {
Id int64 `qbs:"index"`
Worth float64
KeyPre int64 `qbs:"unique"
keySub int64
Hash string `qbs:"size:40,index"`
User int64
Time time.Time
}
其中的 keySub
不需要导出,在调用 CreateTableIfNotExists
,提示如下错误:
panic: reflect.Value.Interface: cannot return value obtained from unexported field or method
goroutine 1 [running]:
reflect.valueInterface(0x501560, 0x126a9ed8, 0x67, 0x126ac301, 0x1, ...)
D:/workspace/golang/sdk/1.1/src/pkg/reflect/value.go:983 +0x99
reflect.Value.Interface(0x501560, 0x126a9ed8, 0x67, 0x0, 0x0, ...)
D:/workspace/golang/sdk/1.1/src/pkg/reflect/value.go:972 +0x41
github.com/coocood/qbs.structPtrToModel(0x52cc60, 0x126a9ec0, 0x1d0001, 0x0, 0x0, ...)
D:/workspace/golang/3rdparty/src/github.com/coocood/qbs/model.go:194 +0x468
github.com/coocood/qbs.(*Migration).CreateTableIfNotExists(0x126bce20, 0x52cc60, 0x126a9ec0, 0x1, 0x1, ...)
D:/workspace/golang/3rdparty/src/github.com/coocood/qbs/migration.go:19 +0x4b
应该是 model.go
在反射字段时,未排查unexported field
coocood commented
Thanks for the bug report, I'll fix it soon.
tioncai commented
建议还可以增加tag:
`qbs:"ignore"`
忽略不需要持久化的字段。
coocood commented
已经有了qbs:"-"
tioncai commented
好的,谢谢。