mirror of
				https://github.com/3ybactuk/marketplace-go-service-project.git
				synced 2025-10-31 22:43:45 +03:00 
			
		
		
		
	
		
			
				
	
	
		
			19 lines
		
	
	
		
			431 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			19 lines
		
	
	
		
			431 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| 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)
 | |
| }
 | 
