Documentation ¶
Index ¶
Constants ¶
View Source
const (
ContextKey = "StandardAuth"
)
Variables ¶
This section is empty.
Functions ¶
func GetHttpMiddleware ¶
func GetHttpMiddleware( whitePaths, loginPaths, logoutPaths []string, loginByTokenFunc func(ctx context.Context, token string) (*User, error), getLoginTokenFunc func(r *ghttp.Request) string, cookieExpire time.Duration, ) func(r *ghttp.Request)
GetHttpMiddleware 获取http鉴权中间件
参数说明: whitePaths 不需要校验的接口path loginPaths 登入的接口path logoutPaths 登出的接口path loginByTokenFunc 根据token获取鉴权用户信息的方法 getLoginTokenFunc 从登录类接口响应信息中获取token的方法,如 r.GetHandlerResponse().(*v1.UserLoginRes).Token cookieExpire cookie有效期
Types ¶
type ContextValue ¶
type ContextValue struct {
User *User // 登录用户信息
}
type StandardAuthContext ¶
type StandardAuthContext interface { InitRUser(r *ghttp.Request, user *User) InitUser(ctx context.Context, user *User) context.Context Get(ctx context.Context) *ContextValue GetUser(ctx context.Context) *User GetUserWithCheck(ctx context.Context) (ret *User, err error) }
func GetStandardAuth ¶
func GetStandardAuth() StandardAuthContext
Click to show internal directories.
Click to hide internal directories.