You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
435 B
Go
20 lines
435 B
Go
4 years ago
|
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)
|
||
|
}
|
||
|
}
|