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?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?