( failover *sentinelFailover, )
| 577 | } |
| 578 | |
| 579 | func masterReplicaDialer( |
| 580 | failover *sentinelFailover, |
| 581 | ) func(ctx context.Context, network, addr string) (net.Conn, error) { |
| 582 | return func(ctx context.Context, network, _ string) (net.Conn, error) { |
| 583 | var addr string |
| 584 | var err error |
| 585 | |
| 586 | if failover.opt.ReplicaOnly { |
| 587 | addr, err = failover.RandomReplicaAddr(ctx) |
| 588 | } else { |
| 589 | addr, err = failover.MasterAddr(ctx) |
| 590 | if err == nil { |
| 591 | failover.trySwitchMaster(ctx, addr) |
| 592 | } |
| 593 | } |
| 594 | if err != nil { |
| 595 | return nil, err |
| 596 | } |
| 597 | if failover.opt.Dialer != nil { |
| 598 | return failover.opt.Dialer(ctx, network, addr) |
| 599 | } |
| 600 | |
| 601 | netDialer := &net.Dialer{ |
| 602 | Timeout: failover.opt.DialTimeout, |
| 603 | KeepAlive: 5 * time.Minute, |
| 604 | } |
| 605 | if failover.opt.TLSConfig == nil { |
| 606 | return netDialer.DialContext(ctx, network, addr) |
| 607 | } |
| 608 | return tls.DialWithDialer(netDialer, network, addr, failover.opt.TLSConfig) |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | //------------------------------------------------------------------------------ |
| 613 |
no test coverage detected