diff --git a/v.go b/v.go index 38be34d..ea9c757 100644 --- a/v.go +++ b/v.go @@ -56,7 +56,9 @@ func Struct(structure interface{}) error { // recurse if this is an embedded struct if value.Kind() == reflect.Struct && field.PkgPath == "" { // only exported fields should do this - return Struct(value.Interface()) + if err := Struct(value.Interface()); err != nil { + return err + } } // get all the v tags diff --git a/v_test.go b/v_test.go index 2b3e1b0..a2f87a4 100644 --- a/v_test.go +++ b/v_test.go @@ -130,6 +130,25 @@ func TestStruct(t *testing.T) { } } +func Test_Embedding(t *testing.T) { + type A struct { + StrField string `v:"between:0..10"` + } + type B struct { + A + IntField int `v:"between:0..10"` + } + err := Struct(B{ + A: A{ + StrField: "hello world!", // this is not ok + }, + IntField: 10, // this is ok + }) + if err == nil { + t.Error("This should fail") + } +} + func Test_validationErorrs_Error(t *testing.T) { tests := []struct { name string