Documentation
¶
Index ¶
- func Get(v any) ([]*http.Cookie, error)
- func GetJSON(v any) ([]byte, error)
- func GetString(v any) string
- func MustGet(v any) []*http.Cookie
- func Set(v any, cookies []*http.Cookie) error
- func SetJSON(v any, data []byte) error
- type ForcedRefresher
- type KeepaliveCookieJar
- func (k *KeepaliveCookieJar) Keepalive(ctx context.Context, delayer req.Delayer, delay ...time.Duration)
- func (k *KeepaliveCookieJar) Run()
- func (k *KeepaliveCookieJar) SinceLastVerified() time.Duration
- func (k *KeepaliveCookieJar) State() State
- func (k *KeepaliveCookieJar) StopKeepalive()
- func (k *KeepaliveCookieJar) Verify(ctx context.Context)
- type Pool
- type Refresher
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ForcedRefresher ¶
ForcedRefresher 强制刷新器,每次检测时都认定 http.CookieJar 已失效,并将自身用于刷新
type KeepaliveCookieJar ¶
type KeepaliveCookieJar struct {
// 任意 http.CookieJar 实例
http.CookieJar
// 刷新器
Refresher Refresher
// 错误上报
OnError func(error)
// contains filtered or unexported fields
}
KeepaliveCookieJar 是支持自动保活的 http.CookieJar
func Keepalive ¶
func Keepalive(jar http.CookieJar, refresher Refresher, delayer req.Delayer, delay ...time.Duration) *KeepaliveCookieJar
Keepalive 立即开始保活 http.CookieJar
func KeepaliveWithContext ¶
func KeepaliveWithContext(ctx context.Context, jar http.CookieJar, refresher Refresher, delayer req.Delayer, delay ...time.Duration) *KeepaliveCookieJar
KeepaliveWithContext 携带上下文立即开始保活 http.CookieJar
func (*KeepaliveCookieJar) Keepalive ¶
func (k *KeepaliveCookieJar) Keepalive(ctx context.Context, delayer req.Delayer, delay ...time.Duration)
Keepalive 保活 http.CookieJar ,延迟器决定每次保活的间隔, 延时决定是否预先进行一次检测,传入正数则在延时后检测,不传入则立即检测,传入非正数则不预先检测
func (*KeepaliveCookieJar) SinceLastVerified ¶
func (k *KeepaliveCookieJar) SinceLastVerified() time.Duration
SinceLastVerified 获取距离上次验证成功时过去的时间
func (*KeepaliveCookieJar) State ¶
func (k *KeepaliveCookieJar) State() State
State 获取 http.CookieJar 的验证状态
func (*KeepaliveCookieJar) StopKeepalive ¶
func (k *KeepaliveCookieJar) StopKeepalive()
StopKeepalive 主动取消保活 http.CookieJar
func (*KeepaliveCookieJar) Verify ¶
func (k *KeepaliveCookieJar) Verify(ctx context.Context)
Verify 携带上下文检测 http.CookieJar 是否有效
type Pool ¶
type Pool struct {
// 检测 http.CookieJar 是否有效的时间间隔
Refresh time.Duration
// 错误上报
OnError func(error)
// contains filtered or unexported fields
}
Pool 是自动保活的 http.CookieJar 的池,可以获取随机已验证的实例
func (*Pool) Add ¶
func (p *Pool) Add(jar http.CookieJar, refresher Refresher, delay ...time.Duration) *KeepaliveCookieJar
Add 添加 http.CookieJar 并且开始保活
func (*Pool) Get ¶
func (p *Pool) Get(index ...int) []*KeepaliveCookieJar
Get 获取有效下标的 http.CookieJar ,不指定下标时返回全部 http.CookieJar
type Refresher ¶
type Refresher interface {
// IsValid 检测 http.CookieJar 是否有效
IsValid(context.Context, http.CookieJar) (bool, error)
// Refresh 刷新 http.CookieJar
Refresh(context.Context, http.CookieJar) error
}
Refresher 刷新器,用于检测和刷新 http.CookieJar
Click to show internal directories.
Click to hide internal directories.