我可以看到scanner.go该结构有一个error方法。
// A SyntaxError is a description of a JSON syntax error.
type SyntaxError struct {
msg string // description of error
Offset int64 // error occurred after reading Offset bytes
}
func (e *SyntaxError) Error() string { return e.msg }
但是编译器告诉我这个:
api/errors.go:24: impossible type switch case: err (type error) cannot have dynamic type json.SyntaxError (missing Error method) 尝试在类型上做开关盒时
func myFunction(err error) {
switch err.(type) {
case validator.ErrorMap, json.SyntaxError:
response.WriteErrorString(http.StatusBadRequest, "400: Bad Request")
//etc
为什么这不能编译?因为结构有Error方法。
肥皂起泡泡
相关分类