Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Freeaqingme/c491d5d743f5a9dda3b7565e2e054745 to your computer and use it in GitHub Desktop.
Save Freeaqingme/c491d5d743f5a9dda3b7565e2e054745 to your computer and use it in GitHub Desktop.
Golang GRPC Unix Socket
conn, err := grpc.Dial(
s.rpcSocketPath,
grpc.WithInsecure(),
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", addr, timeout)
}))
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := pb.NewGreeterClient(conn)
// Contact the server and print out its response.
hostname, _ := os.Hostname()
r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: hostname + "-worker"})
if err != nil {
log.Fatalf("could not greet: %v", err)
}
log.Printf("Greeting: %s", r.Message)
@logrusorgru
Copy link

Doesn't it work with unix://addr?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment