2
scanner.go
にstructがerror
メソッドを持っていることがわかります。goコンパイラが構造体がインタフェースを満たしていないと言っているのはなぜですか?
// 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 }
しかし、コンパイラは、この私に語った:タイプ
func myFunction(err error) {
switch err.(type) {
case validator.ErrorMap, json.SyntaxError:
response.WriteErrorString(http.StatusBadRequest, "400: Bad Request")
//etc
にスイッチケースをやろうとしたときに
api/errors.go:24: impossible type switch case: err (type error) cannot have dynamic type json.SyntaxError (missing Error method)
なぜこれがコンパイルされませんか?構造体にはError
メソッドがあるためです。