From a424cf46cceeff30348b6f0791b38b9a4411a081 Mon Sep 17 00:00:00 2001 From: Jonas Hsiao Date: Sat, 29 Jul 2023 09:17:05 +0800 Subject: [PATCH] feat(tonic): Support register a validation function allowing context --- tonic/handler.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tonic/handler.go b/tonic/handler.go index 1009055..0f02836 100644 --- a/tonic/handler.go +++ b/tonic/handler.go @@ -150,6 +150,15 @@ func RegisterValidation(tagName string, validationFunc validator.Func) error { return validatorObj.RegisterValidation(tagName, validationFunc) } +// RegisterValidationCtx does the same as RegisterValidation on accepts a validator.FuncCtx validation +// allowing context.Context validation support. +// NOTE: calling this function may instantiate the validator itself. +// NOTE: this function is not thread safe, since the validator validation registration isn't +func RegisterValidationCtx(tagName string, validationFuncCtx validator.FuncCtx) error { + initValidator() + return validatorObj.RegisterValidationCtx(tagName, validationFuncCtx) +} + // RegisterTagNameFunc registers a function to get alternate names for StructFields. // // eg. to use the names which have been specified for JSON representations of structs, rather than normal Go field names: