rename rpcx to zrpc
This commit is contained in:
18
zrpc/internal/serverinterceptors/timeoutinterceptor.go
Normal file
18
zrpc/internal/serverinterceptors/timeoutinterceptor.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package serverinterceptors
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/tal-tech/go-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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user