VarWithKeyCtx validates a single variable with a key to be included in the returned error using tag style validation and allows passing of contextual validation information via context.Context. eg. var s string validate.VarWithKeyCtx("email_address", s, "required,email") WARNING: a struct can be pa
(ctx context.Context, key string, field interface{}, tag string)
| 714 | // You will need to assert the error if it's not nil eg. err.(validator.ValidationErrors) to access the array of errors. |
| 715 | // validate Array, Slice and maps fields which may contain more than one error |
| 716 | func (v *Validate) VarWithKeyCtx(ctx context.Context, key string, field interface{}, tag string) (err error) { |
| 717 | if len(tag) == 0 || tag == skipValidationTag { |
| 718 | return nil |
| 719 | } |
| 720 | |
| 721 | ctag := v.fetchCacheTag(tag) |
| 722 | |
| 723 | cField := &cField{ |
| 724 | name: key, |
| 725 | altName: key, |
| 726 | namesEqual: true, |
| 727 | } |
| 728 | |
| 729 | val := reflect.ValueOf(field) |
| 730 | vd := v.pool.Get().(*validate) |
| 731 | vd.top = val |
| 732 | vd.isPartial = false |
| 733 | vd.traverseField(ctx, val, val, vd.ns[0:0], vd.actualNs[0:0], cField, ctag) |
| 734 | |
| 735 | if len(vd.errs) > 0 { |
| 736 | err = vd.errs |
| 737 | vd.errs = nil |
| 738 | } |
| 739 | v.pool.Put(vd) |
| 740 | return |
| 741 | } |
| 742 | |
| 743 | func (v *Validate) registerValidation(tag string, fn FuncCtx, bakedIn bool, nilCheckable bool) error { |
| 744 | if len(tag) == 0 { |