Skip to content

Commit e303769

Browse files
author
Dean Karn
authored
Merge pull request #304 from aaronlehmann/doc-fixes
Documentation fixes
2 parents 893aecc + 770163b commit e303769

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

baked_in.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import (
1111
"unicode/utf8"
1212
)
1313

14-
// Func accepts a FieldLevel interface for all validation needs
14+
// Func accepts a FieldLevel interface for all validation needs. The return
15+
// value should be true when validation succeeds.
1516
type Func func(fl FieldLevel) bool
1617

17-
// FuncCtx accepts a context.Context and FieldLevel interface for all validation needs
18+
// FuncCtx accepts a context.Context and FieldLevel interface for all
19+
// validation needs. The return value should be true when validation succeeds.
1820
type FuncCtx func(ctx context.Context, fl FieldLevel) bool
1921

2022
// wrapFunc wraps noramal Func makes it compatible with FuncCtx

errors.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ type FieldError interface {
101101
// returns the namespace for the field error, with the tag
102102
// name taking precedence over the fields actual name.
103103
//
104-
// eq. JSON name "User.fname" see ActualNamespace for comparison
104+
// eg. JSON name "User.fname"
105+
//
106+
// See StructNamespace() for a version that returns actual names.
105107
//
106108
// NOTE: this field can be blank when validating a single primitive field
107109
// using validate.Field(...) as there is no way to extract it's name

struct_level.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ type StructLevel interface {
5252
//
5353
// tag can be an existing validation tag or just something you make up
5454
// and process on the flip side it's up to you.
55-
ReportError(field interface{}, fieldName, altName, tag, param string)
55+
ReportError(field interface{}, fieldName, structFieldName string, tag, param string)
5656

5757
// reports an error just by passing ValidationErrors
5858
//
@@ -63,9 +63,6 @@ type StructLevel interface {
6363
// eg. pass 'User.FirstName' or 'Users[0].FirstName' depending
6464
// on the nesting. most of the time they will be blank, unless you validate
6565
// at a level lower the the current field depth
66-
//
67-
// tag can be an existing validation tag or just something you make up
68-
// and process on the flip side it's up to you.
6966
ReportValidationErrors(relativeNamespace, relativeActualNamespace string, errs ValidationErrors)
7067
}
7168

validator_instance.go

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -176,25 +176,17 @@ func (v *Validate) RegisterAlias(alias, tags string) {
176176
}
177177

178178
// RegisterStructValidation registers a StructLevelFunc against a number of types.
179-
// This is akin to implementing the 'Validatable' interface, but for structs for which
180-
// you may not have access or rights to change.
181179
//
182-
// NOTES:
183-
// - if this and the 'Validatable' interface are implemented the Struct Level takes precedence as to enable
184-
// a struct out of your control's validation to be overridden
180+
// NOTE:
185181
// - this method is not thread-safe it is intended that these all be registered prior to any validation
186182
func (v *Validate) RegisterStructValidation(fn StructLevelFunc, types ...interface{}) {
187183
v.RegisterStructValidationCtx(wrapStructLevelFunc(fn), types...)
188184
}
189185

190186
// RegisterStructValidationCtx registers a StructLevelFuncCtx against a number of types and allows passing
191187
// of contextual validation information via context.Context.
192-
// This is akin to implementing a 'Validatable' interface, but for structs for which
193-
// you may not have access or rights to change.
194188
//
195-
// NOTES:
196-
// - if this and the 'Validatable' interface are implemented the Struct Level takes precedence as to enable
197-
// a struct out of your control's validation to be overridden
189+
// NOTE:
198190
// - this method is not thread-safe it is intended that these all be registered prior to any validation
199191
func (v *Validate) RegisterStructValidationCtx(fn StructLevelFuncCtx, types ...interface{}) {
200192

@@ -494,9 +486,10 @@ func (v *Validate) StructExceptCtx(ctx context.Context, s interface{}, fields ..
494486
// var i int
495487
// validate.Var(i, "gt=1,lt=10")
496488
//
497-
// WARNING: a struct can be passed for validation eg. time.Time is a struct or if you have a custom type and have registered
498-
// a custom type handler, so must allow it; however unforseen validations will occur if trying to validate a struct
499-
// that is meant to be passed to 'validate.Struct'
489+
// WARNING: a struct can be passed for validation eg. time.Time is a struct or
490+
// if you have a custom type and have registered a custom type handler, so must
491+
// allow it; however unforseen validations will occur if trying to validate a
492+
// struct that is meant to be passed to 'validate.Struct'
500493
//
501494
// It returns InvalidValidationError for bad values passed in and nil or ValidationErrors as error otherwise.
502495
// You will need to assert the error if it's not nil eg. err.(validator.ValidationErrors) to access the array of errors.
@@ -511,9 +504,10 @@ func (v *Validate) Var(field interface{}, tag string) error {
511504
// var i int
512505
// validate.Var(i, "gt=1,lt=10")
513506
//
514-
// WARNING: a struct can be passed for validation eg. time.Time is a struct or if you have a custom type and have registered
515-
// a custom type handler, so must allow it; however unforseen validations will occur if trying to validate a struct
516-
// that is meant to be passed to 'validate.Struct'
507+
// WARNING: a struct can be passed for validation eg. time.Time is a struct or
508+
// if you have a custom type and have registered a custom type handler, so must
509+
// allow it; however unforseen validations will occur if trying to validate a
510+
// struct that is meant to be passed to 'validate.Struct'
517511
//
518512
// It returns InvalidValidationError for bad values passed in and nil or ValidationErrors as error otherwise.
519513
// You will need to assert the error if it's not nil eg. err.(validator.ValidationErrors) to access the array of errors.
@@ -562,9 +556,10 @@ func (v *Validate) VarCtx(ctx context.Context, field interface{}, tag string) (e
562556
// s2 := "abcd"
563557
// validate.VarWithValue(s1, s2, "eqcsfield") // returns true
564558
//
565-
// WARNING: a struct can be passed for validation eg. time.Time is a struct or if you have a custom type and have registered
566-
// a custom type handler, so must allow it; however unforseen validations will occur if trying to validate a struct
567-
// that is meant to be passed to 'validate.Struct'
559+
// WARNING: a struct can be passed for validation eg. time.Time is a struct or
560+
// if you have a custom type and have registered a custom type handler, so must
561+
// allow it; however unforseen validations will occur if trying to validate a
562+
// struct that is meant to be passed to 'validate.Struct'
568563
//
569564
// It returns InvalidValidationError for bad values passed in and nil or ValidationErrors as error otherwise.
570565
// You will need to assert the error if it's not nil eg. err.(validator.ValidationErrors) to access the array of errors.
@@ -580,9 +575,10 @@ func (v *Validate) VarWithValue(field interface{}, other interface{}, tag string
580575
// s2 := "abcd"
581576
// validate.VarWithValue(s1, s2, "eqcsfield") // returns true
582577
//
583-
// WARNING: a struct can be passed for validation eg. time.Time is a struct or if you have a custom type and have registered
584-
// a custom type handler, so must allow it; however unforseen validations will occur if trying to validate a struct
585-
// that is meant to be passed to 'validate.Struct'
578+
// WARNING: a struct can be passed for validation eg. time.Time is a struct or
579+
// if you have a custom type and have registered a custom type handler, so must
580+
// allow it; however unforseen validations will occur if trying to validate a
581+
// struct that is meant to be passed to 'validate.Struct'
586582
//
587583
// It returns InvalidValidationError for bad values passed in and nil or ValidationErrors as error otherwise.
588584
// You will need to assert the error if it's not nil eg. err.(validator.ValidationErrors) to access the array of errors.

0 commit comments

Comments
 (0)