From 4cb8d0f0af0d15cab8b508bf1a8485e422798cd7 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 23 Sep 2019 13:58:50 +0200 Subject: [PATCH] Options#init(): auto-detect *nix socket address --- options.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/options.go b/options.go index 54c6fae..066cbca 100644 --- a/options.go +++ b/options.go @@ -99,12 +99,16 @@ type Options struct { } func (opt *Options) init() { - if opt.Network == "" { - opt.Network = "tcp" - } if opt.Addr == "" { opt.Addr = "localhost:6379" } + if opt.Network == "" { + if strings.HasPrefix(opt.Addr, "/") { + opt.Network = "unix" + } else { + opt.Network = "tcp" + } + } if opt.Dialer == nil { opt.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) { netDialer := &net.Dialer{