Go checking for the type of a custom Error

I have manged to make an error assertion using the switch statement as follows:

 err := FuncModelMissingError()

 switch t := err.(type) {
 default:
     fmt.Println("not a model missing error")
 case *ModelMissingError:
     fmt.Println("ModelMissingError", t)
}

I hope this helps you out.


Reading the Blog post further exposes a bit of Go like this:

serr, ok := err.(*model.ModelMissingError)

This is the comma ok idiom, clearly I need to re do my go lang tour