25 lines
557 B
Go
25 lines
557 B
Go
![]() |
package client
|
||
|
|
||
|
import "context"
|
||
|
|
||
|
type Auth struct {
|
||
|
isTLS bool
|
||
|
Value string
|
||
|
}
|
||
|
|
||
|
const headerAuthorize string = "authorization"
|
||
|
|
||
|
func (a *Auth) SetIsTLS(status bool) {
|
||
|
a.isTLS = status
|
||
|
}
|
||
|
|
||
|
// GetRequestMetadata 获取当前请求认证所需的元数据
|
||
|
func (a *Auth) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
|
||
|
return map[string]string{headerAuthorize: a.Value}, nil
|
||
|
}
|
||
|
|
||
|
// RequireTransportSecurity 是否需要基于 TLS 认证进行安全传输
|
||
|
func (a *Auth) RequireTransportSecurity() bool {
|
||
|
return a.isTLS
|
||
|
}
|