balancer

package
v1.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Most of the code here is taken from the Google OAuth2 client library at https://github.com/golang/oauth2, especially https://github.com/golang/oauth2/blob/master/transport.go.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoConn = errors.New("no connection")

ErrNoConn no connection error

Functions

func NewClient

func NewClient(b Balancer) *http.Client

NewClient return a http client that applies a roundrobin load balance between serveral HTTP servers

Types

type Balancer

type Balancer interface {
	Get() (Connection, error)
	Connections() []Connection
}

type Connection

type Connection interface {
	URL() *url.URL
	IsBroken() bool
}

type HttpConnection

type HttpConnection struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewHttpConnection

func NewHttpConnection(url *url.URL) *HttpConnection

func (*HttpConnection) Close

func (c *HttpConnection) Close() error

func (*HttpConnection) HeartbeatDuration

func (c *HttpConnection) HeartbeatDuration(d time.Duration) *HttpConnection

func (*HttpConnection) IsBroken

func (c *HttpConnection) IsBroken() bool

func (*HttpConnection) URL

func (c *HttpConnection) URL() *url.URL

type Roundrobin

type Roundrobin struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Roundrobin load balancer

func NewRoundrobin

func NewRoundrobin(conns ...Connection) (*Roundrobin, error)

NewRoundrobin new round robin with connection

func NewRoundrobinFromURL

func NewRoundrobinFromURL(urls ...string) (*Roundrobin, error)

NewRoundrobinFromURL creates a new round-robin balancer from the given urls. it returns error if any of URLs is invalid

func (*Roundrobin) Connections

func (r *Roundrobin) Connections() []Connection

Connections return connections

func (*Roundrobin) Get

func (r *Roundrobin) Get() (Connection, error)

Get connection from pool

type Transport

type Transport struct {
	Base http.RoundTripper
	// contains filtered or unexported fields
}

func (*Transport) CancelRequest

func (t *Transport) CancelRequest(r *http.Request)

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL