// DialWithInfo establishes a new session to the cluster identified by info,
// with the specified options. If either Tag or Password are specified, then
// a Login call on the admin database will be made.
484385
func DialWithInfo(info MongoInfo, opts DialOpts) (*mgo.Session, error) {
	if opts.Timeout == 0 {
		return nil, errors.New("a non-zero Timeout must be specified")
	}

	dialInfo, err := DialInfo(info.Info, opts)
	if err != nil {
		return nil, err
	}

	session, err := mgo.DialWithInfo(dialInfo)
	if err != nil {
		return nil, err
	}

	if opts.SocketTimeout == 0 {
		opts.SocketTimeout = SocketTimeout
	}
	session.SetSocketTimeout(opts.SocketTimeout)

	if opts.PostDial != nil {
		if err := opts.PostDial(session); err != nil {
			session.Close()
			return nil, errors.Annotate(err, "PostDial failed")
		}
	}
	if info.Tag != nil || info.Password != "" {
		user := AdminUser
		if info.Tag != nil {
			user = info.Tag.String()
		}
		if err := Login(session, user, info.Password); err != nil {
			session.Close()
			return nil, errors.Trace(err)
		}
	}
	return session, nil
}
1368228
func DialWithDialer(dialer *net.Dialer, address string) (c *Client, err error) {
	conn, err := dialer.Dial("tcp", address)
	if err != nil {
		return nil, err
	}

	// We don't return to the caller until we try to receive a greeting. As such,
	// there is no way to set the client's Timeout for that action. As a
	// workaround, if the dialer has a timeout set, use that for the connection's
	// deadline.
	if dialer.Timeout > 0 {
		err = conn.SetDeadline(time.Now().Add(dialer.Timeout))
		if err != nil {
			return
		}
	}

	c, err = New(conn)
	return
}
342592
func (a *BucketSortAggregation) SortWithInfo(info SortInfo) *BucketSortAggregation {
	a.sorters = append(a.sorters, info)
	return a
}
99026
func UserInfo(user, password string) Option {
	return func(o *Options) error {
		o.User = user
		o.Password = password
		return nil
	}
}
815315
func DialWithDialer(dialer net.Dialer) DialOption {
	return DialOption{func(do *dialOptions) {
		do.dialer = dialer
	}}
}
613492
func (p *Process) DialInfo() *mgo.DialInfo {
	localhost := net.JoinHostPort("localhost", p.Port)
	info := &mgo.DialInfo{
		Addrs:   []string{localhost},
		Timeout: 5 * time.Second,
		Direct:  true,
	}

	if p.securityEnabled() {
		info.Addrs = []string{p.addr()}
		info.Database = "admin"
		info.Username = "flynn"
		info.Password = p.Password
	}
	return info
}
917760
func DialWithTLSConfig(network, raddr string, priority Priority, tag string, tlsConfig *tls.Config) (*Writer, error) {
	return dialAllParameters(network, raddr, priority, tag, tlsConfig, nil)
}
1305580
func (p *Provider) Dial(network, address string) (net.Conn, error) {
	return p.DialContext(nil, network, address)
}
803692
func (n *NodeService) InfoWithContext(ctx context.Context) (*NodeInfo, *http.Response, error) {
	resource, _ := url.Parse(nodeInfoResourcePath)

	req, err := n.client.NewRequest(ctx, http.MethodGet, resource, nil)

	if err != nil {
		return nil, nil, err
	}

	nodeInfo := new(NodeInfo)

	res, err := n.client.Do(req, nodeInfo)

	if err != nil {
		return nil, res, err
	}

	return nodeInfo, res, nil
}
640345
func DialWithDialerContext(ctx context.Context, network, address string, dialer net.Dialer) (fcgi *FCGIClient, err error) {
	var conn net.Conn
	conn, err = dialer.DialContext(ctx, network, address)
	if err != nil {
		return
	}

	fcgi = &FCGIClient{
		rwc:       conn,
		keepAlive: false,
		reqID:     1,
	}

	return
}
780603
func Dial(addr string, config *Config) (*Client, error) {
	return DialWithDialer(new(net.Dialer), addr, config, nil)
}
320447
func DialContext(ctx context.Context, network string, address string) (*Conn, error) {
	return DefaultDialer.DialContext(ctx, network, address)
}
1030658
func DialWithOptions(raddr string, block BlockCrypt, dataShards, parityShards int) (*UDPSession, error) {
	// network type detection
	udpaddr, err := net.ResolveUDPAddr("udp", raddr)
	if err != nil {
		return nil, errors.Wrap(err, "net.ResolveUDPAddr")
	}
	network := "udp4"
	if udpaddr.IP.To4() == nil {
		network = "udp"
	}

	conn, err := net.ListenUDP(network, nil)
	if err != nil {
		return nil, errors.Wrap(err, "net.DialUDP")
	}

	return NewConn(raddr, block, dataShards, parityShards, conn)
}
1211022
func DialWithLocation(location *time.Location) DialOption {
	return DialOption{func(do *dialOptions) {
		do.location = location
	}}
}
842843
func DialWithNetConn(conn net.Conn) DialOption {
	return DialOption{func(do *dialOptions) {
		do.conn = conn
	}}
}
232786
func DialWithTLS(tlsConfig tls.Config) DialOption {
	return DialOption{func(do *dialOptions) {
		do.tlsConfig = tlsConfig
	}}
}
116102
func Dial(network, address string, opts ...ConnectionOption) (c Connection, err error) {
	conn, err := net.Dial(network, address)
	if err == nil {
		c, err = NewConnection(conn, opts...)
	}
	return
}