mirror of
https://github.com/3ybactuk/marketplace-go-service-project.git
synced 2025-10-30 14:03:45 +03:00
[hw-8] add: comment service
This commit is contained in:
18
comments/infra/grpc/middleware/validate.go
Normal file
18
comments/infra/grpc/middleware/validate.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package mw
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
func Validate(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
|
||||
if v, ok := req.(interface{ Validate() error }); ok {
|
||||
if err := v.Validate(); err != nil {
|
||||
return nil, status.Error(codes.InvalidArgument, err.Error())
|
||||
}
|
||||
}
|
||||
return handler(ctx, req)
|
||||
}
|
||||
Reference in New Issue
Block a user