【发布时间】:2016-08-17 18:47:43
【问题描述】:
我得到如下所示的编译错误,说 ErrFieldMismatch 类型缺少 Error() 方法,但如最后一个代码块所示,它不是。
知道为什么我不能为此执行类型比较吗?
错误
impossible type switch case: err (type error) cannot have dynamic type "google.golang.org/appengine/datastore".ErrFieldMismatch (missing Error method)
我的代码
type Program struct {
aemodel.Base
Name string `json:"name" required:"true"`
Public bool `json:"isPublic"`
Description string `json:"description" required:"true"`
Default bool `json:"isDefault"`
Tags []string `json:"tags"`
// Level int
}
// Load - PropertyLoadSaver interface
func (p *Program) Load(ps []datastore.Property) error {
if err := datastore.LoadStruct(p, ps); err != nil {
switch err.(type) {
case datastore.ErrFieldMismatch: // <-- Failure point
return nil
default:
return err
}
}
return nil
}
应用引擎代码
type ErrFieldMismatch struct {
StructType reflect.Type
FieldName string
Reason string
}
func (e *ErrFieldMismatch) Error() string {
return fmt.Sprintf("datastore: cannot load field %q into a %q: %s",
e.FieldName, e.StructType, e.Reason)
}
【问题讨论】:
标签: google-app-engine go