Skip to content

Commit 277e608

Browse files
committed
Merge branch 'bodokaiser-error-type-2' into v2
Conflicts: examplevalidate_test.go
2 parents 241ea14 + bd1533c commit 277e608

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

examplevalidate_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"fmt"
2121
"sort"
2222

23-
"gopkg.in/validator.v1"
23+
"gopkg.in/validator.v2"
2424
)
2525

2626
// This example demonstrates a custom function to process template text.
@@ -83,9 +83,9 @@ func ExampleValidate() {
8383
// Output:
8484
// Street cannot be empty.
8585
// Invalid due to fields:
86-
// - Age (less than min)
87-
// - Email (regular expression mismatch)
8886
// - Address.Street (zero value)
87+
// - Age (less than min)
88+
// - Email (regular expression mismatch)
8989
}
9090

9191
// This example shows how to use the Valid helper

validator.go

+3
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ func Valid(val interface{}, tags string) error {
267267
// Valid validates a value based on the provided
268268
// tags and returns errors found or nil.
269269
func (mv *Validator) Valid(val interface{}, tags string) error {
270+
if tags == "-" {
271+
return nil
272+
}
270273
v := reflect.ValueOf(val)
271274
if v.Kind() == reflect.Ptr && !v.IsNil() {
272275
return mv.Valid(v.Elem().Interface(), tags)

validator_test.go

+5-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"testing"
2121

2222
. "gopkg.in/check.v1"
23-
"gopkg.in/validator.v1"
23+
"gopkg.in/validator.v2"
2424
)
2525

2626
func Test(t *testing.T) {
@@ -214,13 +214,11 @@ func (ms *MySuite) TestValidateOmittedStructVar(c *C) {
214214
}
215215

216216
t := test1{}
217-
valid, err := validator.Validate(t)
218-
c.Assert(valid, Equals, true)
219-
c.Assert(err, HasLen, 0)
217+
err := validator.Validate(t)
218+
c.Assert(err, IsNil)
220219

221-
valid, errs := validator.Valid(test2{}, "-")
222-
c.Assert(valid, Equals, true)
223-
c.Assert(errs, HasLen, 0)
220+
errs := validator.Valid(test2{}, "-")
221+
c.Assert(errs, IsNil)
224222
}
225223

226224
func (ms *MySuite) TestUnknownTag(c *C) {

0 commit comments

Comments
 (0)