http_client_cluster

package
v0.0.0-...-bbd8ef1 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2018 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoEndpoints        = errors.New("client: no endpoints available")
	ErrTooManyRedirects   = errors.New("client: too many redirects")
	ErrClusterUnavailable = errors.New("client: cluster is unavailable or misconfigured")
	ErrNoLeaderEndpoint   = errors.New("client: no leader endpoint available")
)
View Source
var ClientMap map[string]ConfigClient = make(map[string]ConfigClient, 1)

per host to a client

View Source
var ClientRWLock *sync.RWMutex = new(sync.RWMutex)
View Source
var DefaultRequestTimeout = 10 * time.Second
View Source
var DefaultRetry = 1
View Source
var Redirect = true

Functions

func Debugf

func Debugf(format string, args ...interface{})

func HttpClientClusterDo

func HttpClientClusterDo(request *http.Request) (*http.Response, error)

the Response.Body has closed after reading into body.

func RegLog

func RegLog(logger Log)

func SetClientConfig

func SetClientConfig(scheme, host string, cfg *HttpClusterConfig) error

func SetDefaultConfig

func SetDefaultConfig(defaultRetry int, defaultRequestTimeout time.Duration) error

eg SetDefaultConfig(1, 120*time.Second)

func SetRedirect

func SetRedirect(ok bool)

Types

type ClusterError

type ClusterError struct {
	Errors []error
}

func (*ClusterError) Detail

func (ce *ClusterError) Detail() string

func (*ClusterError) Error

func (ce *ClusterError) Error() string

type ConfigClient

type ConfigClient struct {
	// contains filtered or unexported fields
}

type HttpClusterClient

type HttpClusterClient struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

***********************************************************************

带集群功能的client,封装httpWeightClient

The client with cluster functionality has encapsulate httpWeightClient

***********************************************************************

func GetClient

func GetClient(scheme, host string) (*HttpClusterClient, error)

func New

func New(scheme, host string, cfg *HttpClusterConfig) (*HttpClusterClient, error)

func (*HttpClusterClient) Do

func (c *HttpClusterClient) Do(request *http.Request) (*http.Response, error)

func (*HttpClusterClient) DoRequest

func (c *HttpClusterClient) DoRequest(request *http.Request) (*http.Response, error)

func (*HttpClusterClient) Len

func (c *HttpClusterClient) Len() int

func (*HttpClusterClient) Less

func (c *HttpClusterClient) Less(i, j int) bool

func (*HttpClusterClient) Pop

func (c *HttpClusterClient) Pop() (client interface{})

func (*HttpClusterClient) Push

func (c *HttpClusterClient) Push(client interface{})

func (*HttpClusterClient) Swap

func (c *HttpClusterClient) Swap(i, j int)

type HttpClusterConfig

type HttpClusterConfig struct {

	// A HeaderTimeoutPerRequest of zero means no timeout.
	HeaderTimeoutPerRequest time.Duration
	// retry times when request err
	Retry    int
	Redirect bool
	// cert for request https
	Cert tls.Certificate
}

func DefaultConfig

func DefaultConfig() *HttpClusterConfig

type Log

type Log interface {
	Error(format string, args ...interface{})
	Info(format string, args ...interface{})
	Notice(format string, args ...interface{})
	Warning(format string, args ...interface{})
	Debug(format string, args ...interface{})
}

Jump to

Keyboard shortcuts

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