Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateJwtToken(tokenType TokenType, clientId, userName, key string, jti string, exp int64, ...) (tokenString string, err error)
- func GetLoginUserNameFromToken(ctx *gin.Context, key string) string
- func GetTokenFromRequest(ctx *gin.Context) string
- func HandleErrorToPanicPolestarError(err error, code *ErrorCode)
- func HandleErrorToPanicPolestarErrorWithMessage(err error, code *ErrorCode, detailMessage string)
- func PanicPolestarError(code *ErrorCode, detailMessage string)
- func PanicPolestarErrorByError(code *ErrorCode, err error)
- func ParseJwtToken(tokenString, key string) map[string]interface{}
- func SetApplicationConfigFileName(fileName string)
- func VerifySecretOrPassword(cipher string, plain string) bool
- type AppConfig
- type ErrorCode
- type GrantType
- type PolestarError
- type TokenType
Constants ¶
View Source
const ( // token类型 // 访问token TokenTypeAccessToken TokenType = "access_token" // 刷新token TokenTypeRefreshToken TokenType = "refresh_token" // GrantTypePasswordCredentials 密码模式 GrantTypePasswordCredentials GrantType = "password" // GrantTypeRefreshToken token刷新模式 GrantTypeRefreshToken GrantType = "refresh_token" // 请求参数token key(param、form、header) AccessToken = "access_token" Authorization = "Authorization" // token 内容 // 角色信息 TokenDataRoles = "roles" // 授权信息 TokenDataAuthorities = "authorities" // session数据 TokenDataSession = "session" // token claims // token有效期 ClaimsEXP = "exp" // token唯一标示 ClaimsJTI = "jti" // token类型:access_token,refresh_token ClaimsType = "type" // 客户端ID ClaimsClientId = "client_id" // 用户名 ClaimsUserName = "user_name" // 客户端scope ClaimsScope = "scope" )
Variables ¶
View Source
var ( // HTTP相关 ERR_HTTP_REQUEST_ERROR = &ErrorCode{1000, "请求错误"} ERR_HTTP_AUTH_FAILED = &ErrorCode{1001, "认证错误"} // 业务相关 ERR_BUSINESS_ERROR = &ErrorCode{2000, "业务错误"} // 系统异常相关 ERR_SYS_ERROR = &ErrorCode{9000, "系统错误"} )
View Source
var (
AntPathMatcher = antpath.New()
)
View Source
var (
// ApplicationConfigFileName 系统配置文件名称,默认 application.yaml
ApplicationConfigFileName = "application.yaml"
)
Functions ¶
func GenerateJwtToken ¶
func GetLoginUserNameFromToken ¶
GetLoginUserNameFromToken 从请求的token中获取登录用户名
func GetTokenFromRequest ¶
GetTokenFromRequest 从请求中获取 access token (param、form、header)
func HandleErrorToPanicPolestarError ¶ added in v1.0.5
HandleErrorToPanicPolestarError 处理错误并Panic
func HandleErrorToPanicPolestarErrorWithMessage ¶ added in v1.0.6
HandleErrorToPanicPolestarErrorWithMessage 处理错误并Panic
func PanicPolestarError ¶
PanicPolestarError 抛出PolestarError异常
func PanicPolestarErrorByError ¶
PanicPolestarErrorByError 抛出PolestarError异常
func ParseJwtToken ¶
ParseJwtToken 解析jwt token
func SetApplicationConfigFileName ¶
func SetApplicationConfigFileName(fileName string)
SetApplicationConfigFileName 设置系统配置文件名称
func VerifySecretOrPassword ¶
VerifySecretOrPassword 验证Secret或者密码
Types ¶
type AppConfig ¶
type AppConfig struct { Server struct { Addr string `yaml:"addr"` Mode string `yaml:"mode"` Cors bool `yaml:"cors"` } `yaml:"server"` Mysql struct { Url string `yaml:"url"'` MaxIdleConns int `yaml:"maxIdleConns"` LogMode bool `yaml:"logMode"` } `yaml:"mysql"` Redis struct { Url string `yaml:"url"` DB int `yaml:"db"` } `yaml:"redis"` Auth struct { Cache struct { CleanupInterval time.Duration `yaml:'cleanupInterval'` } `yaml:"cache"` TokenCheck struct { CheckAtServer bool `yaml:"checkAtServer"` CheckEndpoint string `yaml:"checkEndpoint"` } `yaml:"tokenCheck"` Jwt struct { Secret string `yaml:"secret"` } `yaml:"jwt"` TokenExp struct { AccessToken int `yaml:"accessToken"` RefreshToken int `yaml:"refreshToken"` } `yaml:"tokenExp"` AuthUris []authUriInfo `yaml:"authUris"` SkipUris []authUriInfo `yaml:"skipUris"` } }
系统配置文件
type PolestarError ¶
PolestarError PolestarError
func IsPolestarError ¶
func IsPolestarError(src interface{}) (*PolestarError, bool)
IsPolestarError 判断是否是PolestarError
func NewPolestarError ¶
func NewPolestarError(code *ErrorCode, detailMessage string) *PolestarError
NewPolestarError 创建NewPolestarError
Click to show internal directories.
Click to hide internal directories.