httppool

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2020 License: MIT Imports: 10 Imported by: 0

README

go http client pool

for example

defer httppool.Close()

client := httppool.Get(content.Background())
client.Request()
...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("redis: client is closed")
View Source
var ErrPoolTimeout = errors.New("redis: connection pool timeout")

Functions

func Close added in v1.0.1

func Close() error

func CloseClient added in v1.0.1

func CloseClient(c *Client) error

func IdleLen added in v1.0.1

func IdleLen() int

func Len added in v1.0.1

func Len() int

func Put added in v1.0.1

func Put(c *Client)

func Remove added in v1.0.1

func Remove(c *Client, err error)

Types

type Client

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

func Get added in v1.0.1

func Get(ctx context.Context) (*Client, error)

func NewClient

func NewClient(client *http.Client) *Client

func (*Client) Close

func (c *Client) Close() error

func (*Client) Request

func (c *Client) Request(url, method string, header http.Header, body io.Reader) ([]byte, error)

func (*Client) SetCreatedAt

func (c *Client) SetCreatedAt(tm time.Time)

func (*Client) SetUsedAt

func (c *Client) SetUsedAt(tm time.Time)

func (*Client) UsedAt

func (c *Client) UsedAt() time.Time

type ClientPool

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

func NewClientPool

func NewClientPool(opt *Options) *ClientPool

func (*ClientPool) Close

func (p *ClientPool) Close() error

func (*ClientPool) CloseClient

func (p *ClientPool) CloseClient(client *Client) error

func (*ClientPool) Get

func (p *ClientPool) Get(ctx context.Context) (*Client, error)

func (*ClientPool) GetStats added in v1.0.1

func (p *ClientPool) GetStats() *Stats

func (*ClientPool) IdleLen

func (p *ClientPool) IdleLen() int

func (*ClientPool) Len

func (p *ClientPool) Len() int

func (*ClientPool) NewClient

func (p *ClientPool) NewClient(ctx context.Context) (*Client, error)

func (*ClientPool) Put

func (p *ClientPool) Put(client *Client)

func (*ClientPool) ReapStaleClients

func (p *ClientPool) ReapStaleClients() (int, error)

func (*ClientPool) Remove

func (p *ClientPool) Remove(client *Client, reason error)

type Options

type Options struct {
	Dialer  func(context.Context) (*http.Client, error)
	OnClose func(*Client) error

	PoolSize           int
	MinIdleClients     int
	MaxClientAge       time.Duration
	PoolTimeout        time.Duration
	IdleTimeout        time.Duration
	IdleCheckFrequency time.Duration
}

type Pooler

type Pooler interface {
	NewClient(context.Context) (*Client, error)
	CloseClient(*Client) error

	Get(context.Context) (*Client, error)
	Put(*Client)
	Remove(*Client, error)

	Len() int
	IdleLen() int
	GetStats() *Stats

	Close() error
}

type Stats

type Stats struct {
	Hits     uint32 // number of times free client was found in the pool
	Misses   uint32 // number of times free client was NOT found in the pool
	Timeouts uint32 // number of times a wait timeout occurred

	TotalClients uint32 // number of total client in the pool
	IdleClients  uint32 // number of idle client in the pool
	StaleClients uint32 // number of stale client removed from the pool
}

Stats contains pool state information and accumulated stats.

func GetStats added in v1.0.1

func GetStats() *Stats

Jump to

Keyboard shortcuts

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