redial

Golang augmented net.Dialer with connection pooling, cached DNS record IP's with round-robin & random access

  • 所有者: linkosmos/redial
  • 平台:
  • 许可证: BSD 3-Clause "New" or "Revised" License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

redial

Golang augmented net.Dialer with connection pooling, cached DNS record IP's with round-robin & random access.

Notice: you must use single dialer per host

Build Status
GoDoc
Go Report Card
BSD License

Methods

  • New(d net.Dialer, address, port string, cPoolInitial, cPoolMax int) (*Dialer, error)
  • Dial(network, address string) (net.Conn, error)
  • Close()
  • String() string

Example

package main

import (
	"fmt"
	"net"
	"net/http"
	"net/url"

	"github.com/Sirupsen/logrus"
	"github.com/linkosmos/redial"
)

func init() {
	logrus.SetLevel(logrus.DebugLevel)
}

func main() {
	url, _ := url.Parse("http://www.example.org")
	port := "80"
	initialConnectionPool := 1
	maxConnectionsInPool := 3

	dialer, err := redial.New(net.Dialer{}, url.Host, port, initialConnectionPool, maxConnectionsInPool)
	if err != nil {
		fmt.Println("redial.New error", err)
		return
	}

	transport := &http.Transport{
		Dial: dialer.Dial,
	}

	request, err := http.NewRequest("GET", url.String(), nil)
	if err != nil {
		fmt.Println("http.NewRequest", err)
		return
	}

	response, err := transport.RoundTrip(request)
	if err != nil {
		fmt.Println("transport.RoundTrip", err)
		return
	}
	defer response.Body.Close()

	fmt.Println("Response status", response.Status, "for", url)
}

License

Copyright (c) 2015, linkosmos
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this
    list of conditions and the following disclaimer.

  • Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.

  • Neither the name of redial nor the names of its
    contributors may be used to endorse or promote products derived from
    this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

主要指标

概览
名称与所有者linkosmos/redial
主编程语言Go
编程语言Go (语言数: 1)
平台
许可证BSD 3-Clause "New" or "Revised" License
所有者活动
创建于2015-10-27 17:29:13
推送于2018-10-25 14:43:30
最后一次提交2016-02-03 18:45:35
发布数0
用户参与
星数42
关注者数1
派生数5
提交数6
已启用问题?
问题数2
打开的问题数2
拉请求数0
打开的拉请求数1
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?