1 Star 0 Fork 0

zhuchance / kubernetes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
reauth.go 1.10 KB
一键复制 编辑 原始数据 按行查看 历史
package gophercloud
import (
"github.com/racker/perigee"
)
// WithReauth wraps a Perigee request fragment with logic to perform re-authentication
// if it's deemed necessary.
//
// Do not confuse this function with WithReauth()! Although they work together to support reauthentication,
// WithReauth() actually contains the decision-making logic to determine when to perform a reauth,
// while WithReauthHandler() is used to configure what a reauth actually entails.
func (c *Context) WithReauth(ap AccessProvider, f func() error) error {
err := f()
cause, ok := err.(*perigee.UnexpectedResponseCodeError)
if ok && cause.Actual == 401 {
err = c.reauthHandler(ap)
if err == nil {
err = f()
}
}
return err
}
// This is like WithReauth above but returns a perigee Response object
func (c *Context) ResponseWithReauth(ap AccessProvider, f func() (*perigee.Response, error)) (*perigee.Response, error) {
response, err := f()
cause, ok := err.(*perigee.UnexpectedResponseCodeError)
if ok && cause.Actual == 401 {
err = c.reauthHandler(ap)
if err == nil {
response, err = f()
}
}
return response, err
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/meoom/kubernetes.git
git@gitee.com:meoom/kubernetes.git
meoom
kubernetes
kubernetes
v0.7.4

搜索帮助

344bd9b3 5694891 D2dac590 5694891