Documentation
¶
Index ¶
- Constants
- Variables
- func CheckDisableByToken(tokenValue string) error
- func CheckDisableMiddleware() echo.MiddlewareFunc
- func CheckLogin(tokenValue string) error
- func CheckLoginMiddleware() echo.MiddlewareFunc
- func CheckPermissionAndByToken(tokenValue string, permissions []string) error
- func CheckPermissionByToken(tokenValue string, permission string) error
- func CheckPermissionMiddleware(perms ...string) echo.MiddlewareFunc
- func CheckPermissionOrByToken(tokenValue string, permissions []string) error
- func CheckRoleAndByToken(tokenValue string, roles []string) error
- func CheckRoleByToken(tokenValue string, role string) error
- func CheckRoleMiddleware(roles ...string) echo.MiddlewareFunc
- func CheckRoleOrByToken(tokenValue string, roles []string) error
- func Disable(loginID interface{}, duration time.Duration) error
- func GenerateNonce() (string, error)
- func GetDisableTime(loginID interface{}) (int64, error)
- func GetHandler(handler echo.HandlerFunc, annotations ...*Annotation) echo.HandlerFunc
- func GetLoginID(tokenValue string) (string, error)
- func GetLoginIDNotCheck(tokenValue string) (string, error)
- func GetPermissionListByToken(tokenValue string) ([]string, error)
- func GetRoleListByToken(tokenValue string) ([]string, error)
- func GetSaToken(c echo.Context) (*core.SaTokenContext, bool)
- func GetTokenValue(loginID interface{}, device ...string) (string, error)
- func HasPermission(loginID interface{}, permission string) bool
- func HasRole(loginID interface{}, role string) bool
- func IgnoreMiddleware() echo.MiddlewareFunc
- func IsDisable(loginID interface{}) bool
- func IsLogin(tokenValue string) bool
- func Kickout(loginID interface{}, device ...string) error
- func Login(loginID interface{}, device ...string) (string, error)
- func LoginByToken(loginID interface{}, tokenValue string, device ...string) error
- func Logout(loginID interface{}, device ...string) error
- func LogoutByToken(tokenValue string) error
- func NewEchoContext(c echo.Context) adapter.RequestContext
- func RevokeRefreshToken(refreshToken string) error
- func SetManager(mgr *Manager)
- func Untie(loginID interface{}) error
- func VerifyNonce(nonce string) bool
- type Annotation
- type Builder
- type Config
- type CookieConfig
- type EchoContext
- func (e *EchoContext) Abort()
- func (e *EchoContext) Get(key string) (interface{}, bool)
- func (e *EchoContext) GetBody() ([]byte, error)
- func (e *EchoContext) GetClientIP() string
- func (e *EchoContext) GetCookie(key string) string
- func (e *EchoContext) GetHeader(key string) string
- func (e *EchoContext) GetHeaders() map[string][]string
- func (e *EchoContext) GetMethod() string
- func (e *EchoContext) GetPath() string
- func (e *EchoContext) GetPostForm(key string) string
- func (e *EchoContext) GetQuery(key string) string
- func (e *EchoContext) GetQueryAll() map[string][]string
- func (e *EchoContext) GetString(key string) string
- func (e *EchoContext) GetURL() string
- func (e *EchoContext) GetUserAgent() string
- func (e *EchoContext) IsAborted() bool
- func (e *EchoContext) MustGet(key string) any
- func (e *EchoContext) Set(key string, value interface{})
- func (e *EchoContext) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
- func (e *EchoContext) SetCookieWithOptions(options *adapter.CookieOptions)
- func (e *EchoContext) SetHeader(key, value string)
- type Event
- type EventData
- type EventListener
- type EventManager
- type ListenerConfig
- type ListenerFunc
- type Manager
- type NonceManager
- type OAuth2AccessToken
- type OAuth2Client
- type OAuth2GrantType
- type OAuth2Server
- type Plugin
- func (p *Plugin) AuthMiddleware() echo.MiddlewareFunc
- func (p *Plugin) LoginHandler(c echo.Context) error
- func (p *Plugin) PathAuthMiddleware(config *core.PathAuthConfig) echo.MiddlewareFunc
- func (p *Plugin) PermissionRequired(permission string) echo.MiddlewareFunc
- func (p *Plugin) RoleRequired(role string) echo.MiddlewareFunc
- type RefreshTokenInfo
- type RefreshTokenManager
- type RequestContext
- type SaTokenContext
- type Session
- func GetSession(loginID interface{}) (*Session, error)
- func GetSessionByToken(tokenValue string) (*Session, error)
- func GetTokenSession(tokenValue string) (*Session, error)
- func LoadSession(id string, storage Storage, prefix string) (*Session, error)
- func NewSession(id string, storage Storage, prefix string) *Session
- type Storage
- type TokenGenerator
- type TokenInfo
- type TokenStyle
Constants ¶
const ( TokenStyleUUID = core.TokenStyleUUID TokenStyleSimple = core.TokenStyleSimple TokenStyleRandom32 = core.TokenStyleRandom32 TokenStyleRandom64 = core.TokenStyleRandom64 TokenStyleRandom128 = core.TokenStyleRandom128 TokenStyleJWT = core.TokenStyleJWT TokenStyleHash = core.TokenStyleHash TokenStyleTimestamp = core.TokenStyleTimestamp TokenStyleTik = core.TokenStyleTik )
Token style constants | Token风格常量
const ( EventLogin = core.EventLogin EventLogout = core.EventLogout EventKickout = core.EventKickout EventDisable = core.EventDisable EventUntie = core.EventUntie EventRenew = core.EventRenew EventCreateSession = core.EventCreateSession EventDestroySession = core.EventDestroySession EventPermissionCheck = core.EventPermissionCheck EventRoleCheck = core.EventRoleCheck EventAll = core.EventAll )
Event constants | 事件常量
const ( GrantTypeAuthorizationCode = core.GrantTypeAuthorizationCode GrantTypeRefreshToken = core.GrantTypeRefreshToken GrantTypeClientCredentials = core.GrantTypeClientCredentials GrantTypePassword = core.GrantTypePassword )
OAuth2 grant type constants | OAuth2授权类型常量
const Version = core.Version
Version Sa-Token-Go version | Sa-Token-Go版本
Variables ¶
var ( RandomString = core.RandomString IsEmpty = core.IsEmpty IsNotEmpty = core.IsNotEmpty DefaultString = core.DefaultString ContainsString = core.ContainsString RemoveString = core.RemoveString UniqueStrings = core.UniqueStrings MergeStrings = core.MergeStrings MatchPattern = core.MatchPattern )
Utility functions | 工具函数
Functions ¶
func CheckDisableByToken ¶
CheckDisable checks if account is disabled (throws error if disabled) | 检查账号是否被封禁(被封禁则抛出错误)
func CheckDisableMiddleware ¶ added in v0.1.3
func CheckDisableMiddleware() echo.MiddlewareFunc
CheckDisableMiddleware decorator for checking if account is disabled | 检查是否被封禁装饰器
func CheckLogin ¶
CheckLogin checks login status (throws error if not logged in) | 检查登录状态(未登录抛出错误)
func CheckLoginMiddleware ¶ added in v0.1.3
func CheckLoginMiddleware() echo.MiddlewareFunc
CheckLoginMiddleware decorator for login checking | 检查登录装饰器
func CheckPermissionAndByToken ¶
CheckPermissionAnd checks if the account has all specified permissions (AND logic) | 检查账号是否拥有所有指定权限(AND逻辑)
func CheckPermissionByToken ¶
CheckPermission checks if the account has specified permission | 检查账号是否拥有指定权限
func CheckPermissionMiddleware ¶ added in v0.1.3
func CheckPermissionMiddleware(perms ...string) echo.MiddlewareFunc
CheckPermissionMiddleware decorator for permission checking | 检查权限装饰器
func CheckPermissionOrByToken ¶
CheckPermissionOr checks if the account has any of the specified permissions (OR logic) | 检查账号是否拥有指定权限中的任意一个(OR逻辑)
func CheckRoleAndByToken ¶
CheckRoleAnd checks if the account has all specified roles (AND logic) | 检查账号是否拥有所有指定角色(AND逻辑)
func CheckRoleByToken ¶
CheckRole checks if the account has specified role | 检查账号是否拥有指定角色
func CheckRoleMiddleware ¶ added in v0.1.3
func CheckRoleMiddleware(roles ...string) echo.MiddlewareFunc
CheckRoleMiddleware decorator for role checking | 检查角色装饰器
func CheckRoleOrByToken ¶
CheckRoleOr checks if the account has any of the specified roles (OR logic) | 检查账号是否拥有指定角色中的任意一个(OR逻辑)
func GenerateNonce ¶
GenerateNonce generates a new nonce token | 生成新的Nonce令牌
func GetDisableTime ¶
GetDisableTime gets remaining disabled time | 获取账号剩余封禁时间
func GetHandler ¶ added in v0.1.3
func GetHandler(handler echo.HandlerFunc, annotations ...*Annotation) echo.HandlerFunc
GetHandler gets handler with annotations | 获取带注解的处理器
func GetLoginID ¶
GetLoginID gets the login ID from token | 从Token获取登录ID
func GetLoginIDNotCheck ¶
GetLoginIDNotCheck gets login ID without checking | 获取登录ID(不检查)
func GetPermissionListByToken ¶
GetPermissionList gets the permission list for an account | 获取账号的权限列表
func GetRoleListByToken ¶
GetRoleList gets the role list for an account | 获取账号的角色列表
func GetSaToken ¶
func GetSaToken(c echo.Context) (*core.SaTokenContext, bool)
GetSaToken 从Echo上下文获取Sa-Token上下文
func GetTokenValue ¶
GetTokenValue gets the token value for a login ID | 获取登录ID对应的Token值
func HasPermission ¶
HasPermission checks if the account has specified permission (returns bool) | 检查账号是否拥有指定权限(返回布尔值)
func HasRole ¶
HasRole checks if the account has specified role (returns bool) | 检查账号是否拥有指定角色(返回布尔值)
func IgnoreMiddleware ¶ added in v0.1.3
func IgnoreMiddleware() echo.MiddlewareFunc
IgnoreMiddleware decorator to ignore authentication | 忽略认证装饰器
func IsDisable ¶
func IsDisable(loginID interface{}) bool
IsDisable checks if an account is disabled | 检查账号是否被封禁
func LoginByToken ¶
LoginByToken performs login with specified token | 使用指定Token登录
func LogoutByToken ¶
LogoutByToken performs logout by token | 根据Token登出
func NewEchoContext ¶
func NewEchoContext(c echo.Context) adapter.RequestContext
NewEchoContext creates an Echo context adapter | 创建Echo上下文适配器
func RevokeRefreshToken ¶
RevokeRefreshToken revokes a refresh token | 撤销刷新令牌
func SetManager ¶
func SetManager(mgr *Manager)
SetManager sets the global Manager (must be called first) | 设置全局Manager(必须先调用此方法)
func VerifyNonce ¶
VerifyNonce verifies a nonce token | 验证Nonce令牌
Types ¶
type Annotation ¶ added in v0.1.3
type Annotation struct {
CheckLogin bool `json:"checkLogin"`
CheckRole []string `json:"checkRole"`
CheckPermission []string `json:"checkPermission"`
CheckDisable bool `json:"checkDisable"`
Ignore bool `json:"ignore"`
}
Annotation annotation structure | 注解结构体
type Builder ¶
Core types | 核心类型
func NewBuilder ¶
func NewBuilder() *Builder
NewBuilder creates a new builder for fluent configuration | 创建新的Builder构建器(用于流式配置)
type Config ¶
Configuration related types | 配置相关类型
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns default configuration | 返回默认配置
type EchoContext ¶
type EchoContext struct {
// contains filtered or unexported fields
}
EchoContext Echo request context adapter | Echo请求上下文适配器
func (*EchoContext) Abort ¶ added in v0.1.2
func (e *EchoContext) Abort()
Abort implements adapter.RequestContext.
func (*EchoContext) Get ¶
func (e *EchoContext) Get(key string) (interface{}, bool)
Get gets context value | 获取上下文值
func (*EchoContext) GetBody ¶ added in v0.1.2
func (e *EchoContext) GetBody() ([]byte, error)
GetBody implements adapter.RequestContext.
func (*EchoContext) GetClientIP ¶
func (e *EchoContext) GetClientIP() string
GetClientIP gets client IP address | 获取客户端IP地址
func (*EchoContext) GetCookie ¶
func (e *EchoContext) GetCookie(key string) string
GetCookie gets cookie | 获取Cookie
func (*EchoContext) GetHeader ¶
func (e *EchoContext) GetHeader(key string) string
GetHeader gets request header | 获取请求头
func (*EchoContext) GetHeaders ¶ added in v0.1.2
func (e *EchoContext) GetHeaders() map[string][]string
GetHeaders implements adapter.RequestContext.
func (*EchoContext) GetMethod ¶
func (e *EchoContext) GetMethod() string
GetMethod gets request method | 获取请求方法
func (*EchoContext) GetPath ¶
func (e *EchoContext) GetPath() string
GetPath gets request path | 获取请求路径
func (*EchoContext) GetPostForm ¶ added in v0.1.2
func (e *EchoContext) GetPostForm(key string) string
GetPostForm implements adapter.RequestContext.
func (*EchoContext) GetQuery ¶
func (e *EchoContext) GetQuery(key string) string
GetQuery gets query parameter | 获取查询参数
func (*EchoContext) GetQueryAll ¶ added in v0.1.2
func (e *EchoContext) GetQueryAll() map[string][]string
GetQueryAll implements adapter.RequestContext.
func (*EchoContext) GetString ¶ added in v0.1.2
func (e *EchoContext) GetString(key string) string
GetString implements adapter.RequestContext.
func (*EchoContext) GetURL ¶ added in v0.1.2
func (e *EchoContext) GetURL() string
GetURL implements adapter.RequestContext.
func (*EchoContext) GetUserAgent ¶ added in v0.1.2
func (e *EchoContext) GetUserAgent() string
GetUserAgent implements adapter.RequestContext.
func (*EchoContext) IsAborted ¶ added in v0.1.2
func (e *EchoContext) IsAborted() bool
IsAborted implements adapter.RequestContext.
func (*EchoContext) MustGet ¶ added in v0.1.2
func (e *EchoContext) MustGet(key string) any
MustGet implements adapter.RequestContext.
func (*EchoContext) Set ¶
func (e *EchoContext) Set(key string, value interface{})
Set sets context value | 设置上下文值
func (*EchoContext) SetCookie ¶
func (e *EchoContext) SetCookie(name, value string, maxAge int, path, domain string, secure, httpOnly bool)
SetCookie sets cookie | 设置Cookie
func (*EchoContext) SetCookieWithOptions ¶ added in v0.1.2
func (e *EchoContext) SetCookieWithOptions(options *adapter.CookieOptions)
SetCookieWithOptions implements adapter.RequestContext.
func (*EchoContext) SetHeader ¶
func (e *EchoContext) SetHeader(key, value string)
SetHeader sets response header | 设置响应头
type EventManager ¶
type EventManager = core.EventManager
Event related types | 事件相关类型
func NewEventManager ¶
func NewEventManager() *EventManager
NewEventManager creates a new event manager | 创建新的事件管理器
type Manager ¶
Core types | 核心类型
func NewManager ¶
NewManager creates a new authentication manager | 创建新的认证管理器
type NonceManager ¶
type NonceManager = core.NonceManager
Core types | 核心类型
func NewNonceManager ¶
func NewNonceManager(storage Storage, prefix string, ttl ...int64) *NonceManager
NewNonceManager creates a new nonce manager | 创建新的Nonce管理器
type OAuth2Server ¶
type OAuth2Server = core.OAuth2Server
Core types | 核心类型
func GetOAuth2Server ¶
func GetOAuth2Server() *OAuth2Server
GetOAuth2Server gets the OAuth2 server instance | 获取OAuth2服务器实例
func NewOAuth2Server ¶
func NewOAuth2Server(storage Storage, prefix string) *OAuth2Server
NewOAuth2Server creates a new OAuth2 server | 创建新的OAuth2服务器
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin Echo plugin for Sa-Token | Echo插件
func (*Plugin) AuthMiddleware ¶
func (p *Plugin) AuthMiddleware() echo.MiddlewareFunc
AuthMiddleware authentication middleware | 认证中间件
func (*Plugin) LoginHandler ¶
LoginHandler 登录处理器
func (*Plugin) PathAuthMiddleware ¶ added in v0.1.6
func (p *Plugin) PathAuthMiddleware(config *core.PathAuthConfig) echo.MiddlewareFunc
PathAuthMiddleware path-based authentication middleware | 基于路径的鉴权中间件
func (*Plugin) PermissionRequired ¶
func (p *Plugin) PermissionRequired(permission string) echo.MiddlewareFunc
PermissionRequired permission validation middleware | 权限验证中间件
func (*Plugin) RoleRequired ¶
func (p *Plugin) RoleRequired(role string) echo.MiddlewareFunc
RoleRequired role validation middleware | 角色验证中间件
type RefreshTokenInfo ¶
type RefreshTokenInfo = core.RefreshTokenInfo
Core types | 核心类型
func LoginWithRefreshToken ¶
func LoginWithRefreshToken(loginID interface{}, device ...string) (*RefreshTokenInfo, error)
LoginWithRefreshToken performs login and returns both access token and refresh token | 登录并返回访问令牌和刷新令牌
func RefreshAccessToken ¶
func RefreshAccessToken(refreshToken string) (*RefreshTokenInfo, error)
RefreshAccessToken refreshes the access token using a refresh token | 使用刷新令牌刷新访问令牌
type RefreshTokenManager ¶
type RefreshTokenManager = core.RefreshTokenManager
Core types | 核心类型
func NewRefreshTokenManager ¶
func NewRefreshTokenManager(storage Storage, prefix string, cfg *Config) *RefreshTokenManager
NewRefreshTokenManager creates a new refresh token manager | 创建新的刷新令牌管理器
type SaTokenContext ¶
type SaTokenContext = core.SaTokenContext
Core types | 核心类型
func NewContext ¶
func NewContext(ctx RequestContext, mgr *Manager) *SaTokenContext
NewContext creates a new Sa-Token context | 创建新的Sa-Token上下文
type Session ¶
Core types | 核心类型
func GetSession ¶
GetSession gets the session for a login ID | 获取登录ID的Session
func GetSessionByToken ¶
GetSessionByToken gets the session by token | 根据Token获取Session
func GetTokenSession ¶
GetTokenSession gets the token session | 获取Token的Session
func LoadSession ¶
LoadSession loads an existing session | 加载已存在的Session
type TokenGenerator ¶
type TokenGenerator = core.TokenGenerator
Core types | 核心类型
func NewTokenGenerator ¶
func NewTokenGenerator(cfg *Config) *TokenGenerator
NewTokenGenerator creates a new token generator | 创建新的Token生成器
type TokenInfo ¶
Core types | 核心类型
func GetTokenInfo ¶
GetTokenInfo gets token information | 获取Token信息