RegisterStructValidationCtx registers a StructLevelFuncCtx against a number of types and allows passing of contextual validation information via context.Context. NOTE: - this method is not thread-safe it is intended that these all be registered prior to any validation
(fn StructLevelFuncCtx, types ...interface{})
| 261 | // NOTE: |
| 262 | // - this method is not thread-safe it is intended that these all be registered prior to any validation |
| 263 | func (v *Validate) RegisterStructValidationCtx(fn StructLevelFuncCtx, types ...interface{}) { |
| 264 | if v.structLevelFuncs == nil { |
| 265 | v.structLevelFuncs = make(map[reflect.Type]StructLevelFuncCtx) |
| 266 | } |
| 267 | |
| 268 | for _, t := range types { |
| 269 | tv := reflect.ValueOf(t) |
| 270 | if tv.Kind() == reflect.Ptr { |
| 271 | t = reflect.Indirect(tv).Interface() |
| 272 | } |
| 273 | |
| 274 | v.structLevelFuncs[reflect.TypeOf(t)] = fn |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | // RegisterStructValidationMapRules registers validate map rules. |
| 279 | // Be aware that map validation rules supersede those defined on a/the struct if present. |