Restore Unix socket support (#498)

https://github.com/fullstorydev/grpcurl/issues/496

Restore -unix to working properly by default with the default dialer.
This commit is contained in:
zhyuri
2025-03-18 08:47:55 -04:00
committed by GitHub
parent 30f87c1323
commit 614b1687cf
2 changed files with 37 additions and 7 deletions

View File

@@ -484,12 +484,12 @@ func main() {
if *maxMsgSz > 0 {
opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(*maxMsgSz)))
}
network := "tcp"
if isUnixSocket != nil && isUnixSocket() {
network = "unix"
if *authority == "" {
*authority = "localhost"
}
if isUnixSocket != nil && isUnixSocket() && !strings.HasPrefix(target, "unix://") {
// prepend unix:// to the address if it's not already there
// this is to maintain backwards compatibility because the custom dialer is replaced by
// the default dialer in grpc-go.
// https://github.com/fullstorydev/grpcurl/pull/480
target = "unix://" + target
}
var creds credentials.TransportCredentials
if *plaintext {
@@ -557,7 +557,7 @@ func main() {
blockingDialTiming := dialTiming.Child("BlockingDial")
defer blockingDialTiming.Done()
cc, err := grpcurl.BlockingDial(ctx, network, target, creds, opts...)
cc, err := grpcurl.BlockingDial(ctx, "", target, creds, opts...)
if err != nil {
fail(err, "Failed to dial target host %q", target)
}