qrz/vendor/github.com/markbates/errx/errx.go
Paul Lecuq 36c5d6f2ed
Some checks failed
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is failing
large change on qrz
- web service with json support
- web page
- cron service to update database infos
2020-05-09 19:09:27 +02:00

50 lines
622 B
Go

package errx
import "fmt"
// go2 errors
type Wrapper interface {
Unwrap() error
}
// pkg/errors
type Causer interface {
Cause() error
}
func Unwrap(err error) error {
switch e := err.(type) {
case Wrapper:
return e.Unwrap()
case Causer:
return e.Cause()
}
return err
}
var Cause = Unwrap
func Wrap(err error, msg string) error {
return wrapped{
err: err,
msg: msg,
}
}
type wrapped struct {
err error
msg string
}
func (w wrapped) Error() string {
return fmt.Sprintf("%s: %s", w.msg, w.err)
}
func (w wrapped) Unwrap() error {
return w.err
}
func (w wrapped) Cause() error {
return w.err
}