From d041bfe7baf71e27c92bb3242d61ea934b93604a Mon Sep 17 00:00:00 2001 From: lc-1010 <532398960@qq.com> Date: Sun, 16 Jul 2023 17:38:11 +0800 Subject: [PATCH] feat: Add client interceptor - Add client interceptor #16 --- cmd/internal/middleware/client_interceptor.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 cmd/internal/middleware/client_interceptor.go diff --git a/cmd/internal/middleware/client_interceptor.go b/cmd/internal/middleware/client_interceptor.go new file mode 100644 index 0000000..9b5507a --- /dev/null +++ b/cmd/internal/middleware/client_interceptor.go @@ -0,0 +1,15 @@ +package middleware + +import ( + "context" + "time" +) + +func defaultContextTimeout(ctx context.Context) (context.Context, context.CancelFunc) { + var cancel context.CancelFunc + if _, ok := ctx.Deadline(); !ok { + defaultTimeout := 60 * time.Second + ctx, cancel = context.WithTimeout(ctx, defaultTimeout) + } + return ctx, cancel +}