是否可以支持请求的复用
yimingsir opened this issue · comments
yimingsir commented
类似创建一个client,设置全局的header和一些callback函数,以后每次请求就不用重复创建client了。
client = gout.New()
client.
Debug(true).
SetTimeout(time.Duration(cc.timeout) * time.Second).
SetHeader(gout.H{
"Content-Type": "application/json;v=1.0",
"Accept": "application/json",
"Authorization": fmt.Sprintf("Bearer %s", cc.token),
}).F().
Retry().Attempt(3).WaitTime(time.Millisecond * 3).MaxWaitTime(time.Millisecond * 10).
Func(func(c *gout.Context) error {
if c.Error != nil {
return filter.ErrRetry
}
// token过期,重新获取token后重试
if c.Code == 401 {
cc.Login()
return filter.ErrRetry
}
return nil
})
guonaihong commented
这个我考虑了下