Dan*_*son 1 go google-cloud-datastore
我的单元测试失败并显示消息:
&errors.errorString {s:"datastore:unsupported struct field type:sus.Version"}
我有一个测试结构类型,我试图保存到GAE数据存储区:
type foo struct{
sus.Version
}
Run Code Online (Sandbox Code Playgroud)
其中sus.Version是界面:
type Version interface{
GetVersion() int
getVersion() int
incrementVersion()
decrementVersion()
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用两个Version实现运行我的测试,首先它只是int的别名:
type version int
Run Code Online (Sandbox Code Playgroud)
其次作为结构:
type version struct{
val int
}
Run Code Online (Sandbox Code Playgroud)
如果Version接口方法被赋予接收器类型(v *version),它需要是一个指针,因此递减和增量实际上更新它们被调用的版本,而不仅仅是一个副本.我不确定为什么这不起作用,可能是因为它是一个匿名字段?或者因为它是指向int或struct而不是实际的int或struct的指针?
该数据存储包不允许使用的所有类型.特别是,它只允许使用以下类型:
- signed integers (int, int8, int16, int32 and int64), - bool, - string, - float32 and float64, - []byte (up to 1 megabyte in length), - any type whose underlying type is one of the above predeclared types, - ByteString, - *Key, - time.Time (stored with microsecond precision), - appengine.BlobKey, - appengine.GeoPoint, - structs whose fields are all valid value types, - slices of any of the above.
请注意,这不包括"任何接口类型".
| 归档时间: |
|
| 查看次数: |
1040 次 |
| 最近记录: |