mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-07 15:10:01 +08:00
feat(gateway): export WithDialer option for custom gRPC client configuration (#5406)
This commit is contained in:
@@ -329,8 +329,9 @@ func createDescriptorSource(cli zrpc.Client, up Upstream) (grpcurl.DescriptorSou
|
|||||||
return source, nil
|
return source, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// withDialer sets a dialer to create a gRPC client.
|
// WithDialer sets a dialer to create a gRPC client.
|
||||||
func withDialer(dialer func(conf zrpc.RpcClientConf) zrpc.Client) func(*Server) {
|
// This allows customization of gRPC client options, such as message size limits.
|
||||||
|
func WithDialer(dialer func(conf zrpc.RpcClientConf) zrpc.Client) func(*Server) {
|
||||||
return func(s *Server) {
|
return func(s *Server) {
|
||||||
s.dialer = dialer
|
s.dialer = dialer
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func TestMustNewServer(t *testing.T) {
|
|||||||
c.Host = "localhost"
|
c.Host = "localhost"
|
||||||
c.Port = 18881
|
c.Port = 18881
|
||||||
|
|
||||||
s := MustNewServer(c, withDialer(func(conf zrpc.RpcClientConf) zrpc.Client {
|
s := MustNewServer(c, WithDialer(func(conf zrpc.RpcClientConf) zrpc.Client {
|
||||||
return zrpc.MustNewClient(conf, zrpc.WithDialOption(grpc.WithContextDialer(dialer())))
|
return zrpc.MustNewClient(conf, zrpc.WithDialOption(grpc.WithContextDialer(dialer())))
|
||||||
}), WithHeaderProcessor(func(header http.Header) []string {
|
}), WithHeaderProcessor(func(header http.Header) []string {
|
||||||
return []string{"foo"}
|
return []string{"foo"}
|
||||||
|
|||||||
Reference in New Issue
Block a user