File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ type FieldLevel interface {
2525 // returns param for validation against current field
2626 Param () string
2727
28+ // GetTag returns the current validations tag name
2829 GetTag () string
2930
3031 // ExtractType gets the actual underlying type of field value.
@@ -74,7 +75,7 @@ func (v *validate) FieldName() string {
7475 return v .cf .altName
7576}
7677
77- // GetTag returns the tag name of field
78+ // GetTag returns the current validations tag name
7879func (v * validate ) GetTag () string {
7980 return v .ct .tag
8081}
Original file line number Diff line number Diff line change @@ -8984,3 +8984,22 @@ func TestRequiredWithoutAllPointers(t *testing.T) {
89848984 errs = val .Struct (lookup )
89858985 Equal (t , errs , nil )
89868986}
8987+
8988+ func TestGetTag (t * testing.T ) {
8989+ var tag string
8990+
8991+ type Test struct {
8992+ String string `validate:"mytag"`
8993+ }
8994+
8995+ val := New ()
8996+ val .RegisterValidation ("mytag" , func (fl FieldLevel ) bool {
8997+ tag = fl .GetTag ()
8998+ return true
8999+ })
9000+
9001+ var test Test
9002+ errs := val .Struct (test )
9003+ Equal (t , errs , nil )
9004+ Equal (t , tag , "mytag" )
9005+ }
You can’t perform that action at this time.
0 commit comments