Skip to content

Commit

Permalink
change err
Browse files Browse the repository at this point in the history
  • Loading branch information
cadyrov committed Sep 16, 2020
1 parent dd147e9 commit 4e11c1d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ func ValidateStruct(structPtr interface{}, fields ...*FieldRules) goerr.IError {
for _, fr := range fields {
fv := reflect.ValueOf(fr.fieldPtr)
if fv.Kind() != reflect.Ptr {
return verror.NewGoerr(1002)
return verror.NewGoErr(1002)
}
ft := findStructField(value, fv)
if ft == nil {
return verror.NewGoerr(1003)
return verror.NewGoErr(1003)
}
if err := Validate(fv.Elem().Interface(), fr.rules...); err != nil {
if ft.Anonymous {
Expand Down
8 changes: 4 additions & 4 deletions validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Validate(value interface{}, rules ...Rule) goerr.IError {
return nil
}
if code, args := rule.Validate(value); code != 0 {
return verror.NewGoerr(code, args...)
return verror.NewGoErr(code, args...)
}
}

Expand All @@ -61,7 +61,7 @@ func Validate(value interface{}, rules ...Rule) goerr.IError {
}
if v, ok := value.(Validatable); ok {
if code, args := v.Validate(); code != 0 {
return verror.NewGoerr(code, args...)
return verror.NewGoErr(code, args...)
}
return nil
}
Expand All @@ -87,7 +87,7 @@ func validateMap(rv reflect.Value) goerr.IError {
for _, key := range rv.MapKeys() {
if mv := rv.MapIndex(key).Interface(); mv != nil {
if code, args := mv.(Validatable).Validate(); code != 0 {
errs.Stack[fmt.Sprintf("%v", key.Interface())] = verror.NewGoerr(code, args)
errs.Stack[fmt.Sprintf("%v", key.Interface())] = verror.NewGoErr(code, args)
}
}
}
Expand All @@ -105,7 +105,7 @@ func validateSlice(rv reflect.Value) goerr.IError {
for i := 0; i < l; i++ {
if ev := rv.Index(i).Interface(); ev != nil {
if code, args := ev.(Validatable).Validate(); code != 0 {
errs.Stack[strconv.Itoa(i)] = verror.NewGoerr(code, args)
errs.Stack[strconv.Itoa(i)] = verror.NewGoErr(code, args)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions verror/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ func NewErrStack() ErrStack {
}
}

func NewGoerr(code int, args ...interface{}) goerr.IError {
func NewGoErr(code int, args ...interface{}) goerr.IError {
errtxt, ok := mpErr[code]
if !ok {
errtxt = "UnknownError"
}
return goerr.New(fmt.Sprintf(errtxt, args...)).Http(http.StatusBadRequest)
return goerr.New(fmt.Sprintf(errtxt, args...)).HTTP(http.StatusBadRequest)
}

0 comments on commit 4e11c1d

Please sign in to comment.