Files

22 lines
695 B
Go

package interceptor
import (
"context"
"google.golang.org/grpc"
"k8s.io/klog/v2"
)
// ApiServerInterceptor implements UnaryServerInterceptor that provides the common wrapping logic
// to be executed before and after all API handler calls, e.g. Logging, error handling.
// For more details, see https://github.com/grpc/grpc-go/blob/master/interceptor.go
func ApiServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
klog.Infof("%v handler starting", info.FullMethod)
resp, err = handler(ctx, req)
if err != nil {
klog.Warning(err)
}
klog.Infof("%v handler finished", info.FullMethod)
return
}