package sqaffold import "net/http" var ( ErrNoRows = NewError(http.StatusNotFound, "no rows", nil) ) type Error struct { StatusCode int Text string Previous error } func (e *Error) Error() string { return e.Text } func (e *Error) Is(target error) bool { if other, ok := target.(*Error); ok { if other.StatusCode > 0 { if e.StatusCode != other.StatusCode { return false } } if other.Text != "" { if e.Text != other.Text { return false } } } return true } func Err(err error) *Error { return NewError(http.StatusInternalServerError, err.Error(), err) } func NewError(statusCode int, text string, previous error) *Error { err := &Error{ StatusCode: statusCode, Text: text, Previous: previous, } return err }