53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package consts
|
|
|
|
// AuthType 认证类型枚举
|
|
type AuthType string
|
|
|
|
const (
|
|
AuthTypeAPIKey AuthType = "api_key" // API密钥
|
|
AuthTypeOAuth AuthType = "oauth" // OAuth
|
|
AuthTypeBasic AuthType = "basic" // Basic认证
|
|
)
|
|
|
|
// GetAllAuthTypes 获取所有认证类型
|
|
func GetAllAuthTypes() []AuthType {
|
|
return []AuthType{
|
|
AuthTypeAPIKey,
|
|
AuthTypeOAuth,
|
|
AuthTypeBasic,
|
|
}
|
|
}
|
|
|
|
type AuthTypeKeyValue struct {
|
|
Key AuthType
|
|
Value string
|
|
}
|
|
|
|
var (
|
|
AuthTypeAPIKeyKeyValue = AuthTypeKeyValue{Key: AuthTypeAPIKey, Value: "API密钥"}
|
|
AuthTypeOAuthKeyValue = AuthTypeKeyValue{Key: AuthTypeOAuth, Value: "OAuth"}
|
|
AuthTypeBasicKeyValue = AuthTypeKeyValue{Key: AuthTypeBasic, Value: "Basic认证"}
|
|
)
|
|
|
|
func GetAllAuthTypeKeyValue() []AuthTypeKeyValue {
|
|
return []AuthTypeKeyValue{
|
|
AuthTypeAPIKeyKeyValue,
|
|
AuthTypeOAuthKeyValue,
|
|
AuthTypeBasicKeyValue,
|
|
}
|
|
}
|
|
|
|
var authTypeValueMap = map[AuthType]string{
|
|
AuthTypeAPIKey: AuthTypeAPIKeyKeyValue.Value,
|
|
AuthTypeOAuth: AuthTypeOAuthKeyValue.Value,
|
|
AuthTypeBasic: AuthTypeBasicKeyValue.Value,
|
|
}
|
|
|
|
func GetAuthTypeValueByKey(key AuthType) (value string) {
|
|
value, exists := authTypeValueMap[key]
|
|
if !exists {
|
|
value = "未知认证类型"
|
|
}
|
|
return
|
|
}
|