Impossible type switch case
go
Solution
You have two different types, `Validator` and the pointer type `*Validator`, and these two types have different method sets.
You have only defined an `Error()` method for the pointer while `Validator` doesn't have this method.
What you can do is the following change:
// Error implements error interface
func (v Validator) Error() string {
return ""
}
...
case *Validator, Validator: // You are actually getting a *Validator
This implements `Error()` for both `Validator` and `*Validator`. As the Go specification says:
The method set of any other type T consists of all methods declared with receiver type T. The method set of the corresponding pointer type *T is the set of all methods declared with receiver *T or T (that is, it also contains the method set of T)
Problem
This program does not compile: ``` package main type Validator struct { } // Error implements error interface func (v *Validator) Error() string { return "" } func test() error { return &Validator{} } func main() { switch test().(type) { case nil: println("No error") case Validator: println("Validation error") return default: println("Unknown error") return } } ``` The error is: ``` prog.go:19: impossible type switch case: test() (type error) cannot have dynamic type Validator (missing Error method) ``` But `Validator` struct has method `Error`.