This commit is contained in:
kevin
2020-07-29 18:06:57 +08:00
parent ffddfa62bb
commit aa3ef20011
29 changed files with 47 additions and 48 deletions

View File

@@ -0,0 +1,19 @@
package serverinterceptors
import (
"context"
"time"
"zero/core/contextx"
"google.golang.org/grpc"
)
func UnaryTimeoutInterceptor(timeout time.Duration) grpc.UnaryServerInterceptor {
return func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo,
handler grpc.UnaryHandler) (resp interface{}, err error) {
ctx, cancel := contextx.ShrinkDeadline(ctx, timeout)
defer cancel()
return handler(ctx, req)
}
}