Merge pull request #1165 from Al2Klimov/feature/options-network-unix

Options#init(): auto-detect *nix socket address
This commit is contained in:
Vladimir Mihailenco 2019-09-23 15:39:50 +03:00 committed by GitHub
commit 4b6ad6a953
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -99,12 +99,16 @@ type Options struct {
} }
func (opt *Options) init() { func (opt *Options) init() {
if opt.Network == "" {
opt.Network = "tcp"
}
if opt.Addr == "" { if opt.Addr == "" {
opt.Addr = "localhost:6379" opt.Addr = "localhost:6379"
} }
if opt.Network == "" {
if strings.HasPrefix(opt.Addr, "/") {
opt.Network = "unix"
} else {
opt.Network = "tcp"
}
}
if opt.Dialer == nil { if opt.Dialer == nil {
opt.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) { opt.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) {
netDialer := &net.Dialer{ netDialer := &net.Dialer{