How to use protoc-gen-validate
(PGV) with connect-go
?
#426
Answered
by
s-takehana
s-takehana
asked this question in
Q&A
Replies: 1 comment 8 replies
-
type validator interface {
ValidateAll() error
}
func NewValidationInterceptor() connect.UnaryInterceptorFunc {
interceptor := func(next connect.UnaryFunc) connect.UnaryFunc {
return connect.UnaryFunc(func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
if v, ok := req.Any().(validator); ok {
if err := v.ValidateAll(); err != nil {
return nil, connect.NewError(connect.CodeInvalidArgument, err)
}
}
return next(ctx, req)
})
}
return connect.UnaryInterceptorFunc(interceptor)
} |
Beta Was this translation helpful? Give feedback.
8 replies
Answer selected by
s-takehana
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How to use
protoc-gen-validate
(PGV) withconnect-go
?I want to call
Validate
/ValidateAll
in interceptor func.Beta Was this translation helpful? Give feedback.
All reactions