Skip to content

Commit c88d6a1

Browse files
authored
✨ feat: support grpc custom options (#121)
1 parent 687f4ed commit c88d6a1

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

pkg/config/grpc.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,14 @@ func (e *GRPC) Init(
4545

4646
type Clients map[string]ServerParams
4747

48-
func (cs Clients) makeClient(key string) *grpc.ClientConn {
48+
func (cs Clients) makeClient(key string, opts ...grpc.DialOption) *grpc.ClientConn {
4949
params, ok := cs[key]
5050
if !ok {
5151
return nil
5252
}
53-
opts := make([]grpc.DialOption, 0)
53+
if opts == nil {
54+
opts = make([]grpc.DialOption, 0)
55+
}
5456
if params.CertFile != "" && params.KeyFile != "" {
5557
creds, err := credentials.NewClientTLSFromFile(params.CertFile, params.KeyFile)
5658
if err != nil {
@@ -66,13 +68,13 @@ func (cs Clients) makeClient(key string) *grpc.ClientConn {
6668
timeout.UnaryClientInterceptor(params.Timeout),
6769
))
6870
}
69-
conn, err := grpc.Dial(params.Addr, opts...)
71+
conn, err := grpc.NewClient(params.Addr, opts...)
7072
if err != nil {
7173
return nil
7274
}
7375
return conn
7476
}
7577

76-
func (e *GRPC) GetGRPCClient(key string) *grpc.ClientConn {
77-
return e.Clients.makeClient(key)
78+
func (e *GRPC) GetGRPCClient(key string, opts ...grpc.DialOption) *grpc.ClientConn {
79+
return e.Clients.makeClient(key, opts...)
7880
}

0 commit comments

Comments
 (0)