Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

是否可以支持请求的复用 #287

Open
yimingsir opened this issue May 25, 2021 · 1 comment
Open

是否可以支持请求的复用 #287

yimingsir opened this issue May 25, 2021 · 1 comment

Comments

@yimingsir
Copy link

yimingsir commented May 25, 2021

类似创建一个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
Copy link
Owner

这个我考虑了下

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants