I have a function which return error
:
func foo(i int) error {
err := errors.New("error here")
if i == 1 {
return errors.Wrap(err, "one")
}
if i == 2 {
return errors.Wrap(err, "two")
}
return nil
}
I want to handle an error in the calling function, but to do it, I need to know the context of error. Something like this:
err := foo(i)
switch err.getContext() {
case "foo":
case "bar":
}
I have found causer interface, but I don't know how to use it here.
Or do I need to create the different types (struct
) for each type of error here ?