Skip to content

Commit 4abba2c

Browse files
authored
support optional grpc.DialOption to GetServerConnection (#132)
1 parent a3b2623 commit 4abba2c

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

app/connection.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import (
1212
"google.golang.org/grpc/metadata"
1313
)
1414

15-
func GetServerConnection(c *cli.Context) (context.Context, *grpc.ClientConn, error) {
15+
func GetServerConnection(c *cli.Context, opts ...grpc.DialOption) (context.Context, *grpc.ClientConn, error) {
1616

1717
serverAddr := c.String(ServerFlagName)
18-
var option grpc.DialOption
18+
var credentialOption grpc.DialOption
1919
parts := strings.Split(serverAddr, ":")
2020

2121
if len(parts) != 2 {
@@ -25,16 +25,16 @@ func GetServerConnection(c *cli.Context) (context.Context, *grpc.ClientConn, err
2525
hostname := parts[0]
2626
switch hostname {
2727
case "localhost":
28-
option = grpc.WithInsecure()
28+
credentialOption = grpc.WithInsecure()
2929
default:
30-
option = grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{
30+
credentialOption = grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{
3131
MinVersion: tls.VersionTLS12,
3232
ServerName: hostname,
3333
}))
3434
}
3535
conn, err := grpc.Dial(
3636
serverAddr,
37-
option,
37+
append(opts, credentialOption)...,
3838
)
3939
if err != nil {
4040
return nil, nil, err

0 commit comments

Comments
 (0)