Skip to content

Commit

Permalink
Replace grpc.Dial with grpc.NewClient
Browse files Browse the repository at this point in the history
grpc.Dial and grpc.DialWithContext were deprecated and mention their
replacement as grpc.NewClient. https://pkg.go.dev/google.golang.org/[email protected]#Dial

One consequence of this change is that the target address needs to have
"unix:" or "unix://" prepended to the absolute path for NewClient to
create a connection properly.

Signed-off-by: Michael Shen <[email protected]>
  • Loading branch information
mjlshen committed Nov 12, 2024
1 parent a7a91e5 commit ffdcd1a
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions pkg/connection/connection.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
package connection

import (
"context"
"fmt"
"net"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

// New returns a grpc client connection for a given unix socket file path
func New(addr string) (*grpc.ClientConn, error) {
dialer := func(ctx context.Context, addr string) (net.Conn, error) {
var d net.Dialer
return d.DialContext(ctx, "unix", addr)
}

conn, err := grpc.Dial(
addr, grpc.WithContextDialer(dialer),
conn, err := grpc.NewClient(
"unix://"+addr,
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
Expand Down

0 comments on commit ffdcd1a

Please sign in to comment.