You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
574 B
37 lines
574 B
package validator
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
var (
|
|
ErrInvalid = errors.New("invalid value")
|
|
ErrNotBlank = errors.New("not blank")
|
|
)
|
|
|
|
func NewError(err error, value, expect interface{}) Error {
|
|
return Error{
|
|
err: err,
|
|
value: value,
|
|
expect: expect,
|
|
}
|
|
}
|
|
|
|
type Error struct {
|
|
err error
|
|
value interface{}
|
|
expect interface{}
|
|
}
|
|
|
|
func (e Error) Error() string {
|
|
return fmt.Sprintf("%s: expext: %s, given: %s", e.err, e.expect, e.value)
|
|
}
|
|
|
|
func (e Error) Is(err error) bool {
|
|
return errors.Is(e.err, err)
|
|
}
|
|
|
|
func (e Error) Unwrap() error {
|
|
return e.err
|
|
}
|
|
|