parent
3e8039620d
commit
baa5062803
|
|
@ -45,6 +45,8 @@ var version = noVersion
|
||||||
var (
|
var (
|
||||||
exit = os.Exit
|
exit = os.Exit
|
||||||
|
|
||||||
|
isUnixSocket func() bool // nil when run on non-unix platform
|
||||||
|
|
||||||
flags = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
|
flags = flag.NewFlagSet(os.Args[0], flag.ExitOnError)
|
||||||
|
|
||||||
help = flags.Bool("help", false, prettify(`
|
help = flags.Bool("help", false, prettify(`
|
||||||
|
|
@ -481,6 +483,13 @@ func main() {
|
||||||
if *maxMsgSz > 0 {
|
if *maxMsgSz > 0 {
|
||||||
opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(*maxMsgSz)))
|
opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(*maxMsgSz)))
|
||||||
}
|
}
|
||||||
|
network := "tcp"
|
||||||
|
if isUnixSocket != nil && isUnixSocket() {
|
||||||
|
network = "unix"
|
||||||
|
if *authority == "" {
|
||||||
|
*authority = "localhost"
|
||||||
|
}
|
||||||
|
}
|
||||||
var creds credentials.TransportCredentials
|
var creds credentials.TransportCredentials
|
||||||
if *plaintext {
|
if *plaintext {
|
||||||
if *authority != "" {
|
if *authority != "" {
|
||||||
|
|
@ -547,7 +556,7 @@ func main() {
|
||||||
|
|
||||||
blockingDialTiming := dialTiming.Child("BlockingDial")
|
blockingDialTiming := dialTiming.Child("BlockingDial")
|
||||||
defer blockingDialTiming.Done()
|
defer blockingDialTiming.Done()
|
||||||
cc, err := grpcurl.BlockingDial(ctx, target, creds, opts...)
|
cc, err := grpcurl.BlockingDial(ctx, network, target, creds, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fail(err, "Failed to dial target host %q", target)
|
fail(err, "Failed to dial target host %q", target)
|
||||||
}
|
}
|
||||||
|
|
@ -872,7 +881,8 @@ method's request type will be sent.
|
||||||
The address will typically be in the form "host:port" where host can be an IP
|
The address will typically be in the form "host:port" where host can be an IP
|
||||||
address or a hostname and port is a numeric port or service name. If an IPv6
|
address or a hostname and port is a numeric port or service name. If an IPv6
|
||||||
address is given, it must be surrounded by brackets, like "[2001:db8::1]". For
|
address is given, it must be surrounded by brackets, like "[2001:db8::1]". For
|
||||||
Unix variants, the address must start with schema "unix://" followed by the path.
|
Unix variants, if a -unix=true flag is present, then the address must be the
|
||||||
|
path to the domain socket.
|
||||||
|
|
||||||
Available flags:
|
Available flags:
|
||||||
`, os.Args[0])
|
`, os.Args[0])
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || windows
|
||||||
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris windows
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
var (
|
||||||
|
unix = flags.Bool("unix", false, prettify(`
|
||||||
|
Indicates that the server address is the path to a Unix domain socket.`))
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
isUnixSocket = func() bool {
|
||||||
|
return *unix
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -609,7 +609,7 @@ func ServerTransportCredentials(cacertFile, serverCertFile, serverKeyFile string
|
||||||
// BlockingDial is a helper method to dial the given address, using optional TLS credentials,
|
// BlockingDial is a helper method to dial the given address, using optional TLS credentials,
|
||||||
// and blocking until the returned connection is ready. If the given credentials are nil, the
|
// and blocking until the returned connection is ready. If the given credentials are nil, the
|
||||||
// connection will be insecure (plain-text).
|
// connection will be insecure (plain-text).
|
||||||
func BlockingDial(ctx context.Context, address string, creds credentials.TransportCredentials, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
|
func BlockingDial(ctx context.Context, network, address string, creds credentials.TransportCredentials, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
|
||||||
if creds == nil {
|
if creds == nil {
|
||||||
creds = insecure.NewCredentials()
|
creds = insecure.NewCredentials()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -333,7 +333,7 @@ func createTestServerAndClient(serverCreds, clientCreds credentials.TransportCre
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
cc, err := BlockingDial(ctx, fmt.Sprintf("127.0.0.1:%d", port), clientCreds)
|
cc, err := BlockingDial(ctx, "tcp", fmt.Sprintf("127.0.0.1:%d", port), clientCreds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return e, err
|
return e, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue