Skip to content

Commit 842152e

Browse files
committed
feat(webserver): add UnaryClientInterceptors and StreamClientInterceptors for grpc DialOptions
1 parent ed47ff6 commit 842152e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

pkg/webserver/webserver.interceptors.grpc.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,27 @@ func (f *Factory) StreamServerInterceptors(interceptors ...grpc.StreamServerInte
6868
}
6969
return interceptors
7070
}
71+
72+
func (f *Factory) UnaryClientInterceptors(interceptors ...grpc.UnaryClientInterceptor) []grpc.UnaryClientInterceptor {
73+
// handle request timeout
74+
interceptors = append(interceptors, timeoutlimit.UnaryClientInterceptor(f.fc.HandledTimeoutUnary))
75+
// burst limit
76+
interceptors = append(interceptors, burstlimit.UnaryClientInterceptor(f.fc.MaxConcurrencyUnary, f.fc.BurstLimitTimeoutUnary))
77+
// request id
78+
if f.fc.FillRequestId {
79+
interceptors = append(interceptors, requestid.UnaryClientInterceptor())
80+
}
81+
return interceptors
82+
}
83+
84+
func (f *Factory) StreamClientInterceptors(interceptors ...grpc.StreamClientInterceptor) []grpc.StreamClientInterceptor {
85+
// handle request timeout
86+
interceptors = append(interceptors, timeoutlimit.StreamClientInterceptor(f.fc.HandledTimeoutUnary))
87+
// burst limit
88+
interceptors = append(interceptors, burstlimit.StreamClientInterceptor(f.fc.MaxConcurrencyUnary, f.fc.BurstLimitTimeoutUnary))
89+
// request id
90+
if f.fc.FillRequestId {
91+
interceptors = append(interceptors, requestid.StreamClientInterceptor())
92+
}
93+
return interceptors
94+
}

pkg/webserver/webserver.options.grpc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,7 @@ func (f *Factory) DialOptions(opts ...grpc.DialOption) []grpc.DialOption {
4747
if f.fc.EnableOpenTelemetry {
4848
opts = append(opts, otel.DialOptions()...)
4949
}
50+
opts = append(opts, grpc.WithChainUnaryInterceptor(f.UnaryClientInterceptors()...))
51+
opts = append(opts, grpc.WithChainStreamInterceptor(f.StreamClientInterceptors()...))
5052
return opts
5153
}

0 commit comments

Comments
 (0)