echo

package module
v0.1.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 31, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
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风格常量

View Source
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 | 事件常量

View Source
const (
	GrantTypeAuthorizationCode = core.GrantTypeAuthorizationCode
	GrantTypeRefreshToken      = core.GrantTypeRefreshToken
	GrantTypeClientCredentials = core.GrantTypeClientCredentials
	GrantTypePassword          = core.GrantTypePassword
)

OAuth2 grant type constants | OAuth2授权类型常量

View Source
const Version = core.Version

Version Sa-Token-Go version | Sa-Token-Go版本

Variables

View Source
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

func CheckDisableByToken(tokenValue string) error

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

func CheckLogin(tokenValue string) error

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

func CheckPermissionAndByToken(tokenValue string, permissions []string) error

CheckPermissionAnd checks if the account has all specified permissions (AND logic) | 检查账号是否拥有所有指定权限(AND逻辑)

func CheckPermissionByToken

func CheckPermissionByToken(tokenValue string, permission string) error

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

func CheckPermissionOrByToken(tokenValue string, permissions []string) error

CheckPermissionOr checks if the account has any of the specified permissions (OR logic) | 检查账号是否拥有指定权限中的任意一个(OR逻辑)

func CheckRoleAndByToken

func CheckRoleAndByToken(tokenValue string, roles []string) error

CheckRoleAnd checks if the account has all specified roles (AND logic) | 检查账号是否拥有所有指定角色(AND逻辑)

func CheckRoleByToken

func CheckRoleByToken(tokenValue string, role string) error

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

func CheckRoleOrByToken(tokenValue string, roles []string) error

CheckRoleOr checks if the account has any of the specified roles (OR logic) | 检查账号是否拥有指定角色中的任意一个(OR逻辑)

func Disable

func Disable(loginID interface{}, duration time.Duration) error

Disable disables an account for specified duration | 封禁账号(指定时长)

func GenerateNonce

func GenerateNonce() (string, error)

GenerateNonce generates a new nonce token | 生成新的Nonce令牌

func GetDisableTime

func GetDisableTime(loginID interface{}) (int64, error)

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

func GetLoginID(tokenValue string) (string, error)

GetLoginID gets the login ID from token | 从Token获取登录ID

func GetLoginIDNotCheck

func GetLoginIDNotCheck(tokenValue string) (string, error)

GetLoginIDNotCheck gets login ID without checking | 获取登录ID(不检查)

func GetPermissionListByToken

func GetPermissionListByToken(tokenValue string) ([]string, error)

GetPermissionList gets the permission list for an account | 获取账号的权限列表

func GetRoleListByToken

func GetRoleListByToken(tokenValue string) ([]string, error)

GetRoleList gets the role list for an account | 获取账号的角色列表

func GetSaToken

func GetSaToken(c echo.Context) (*core.SaTokenContext, bool)

GetSaToken 从Echo上下文获取Sa-Token上下文

func GetTokenValue

func GetTokenValue(loginID interface{}, device ...string) (string, error)

GetTokenValue gets the token value for a login ID | 获取登录ID对应的Token值

func HasPermission

func HasPermission(loginID interface{}, permission string) bool

HasPermission checks if the account has specified permission (returns bool) | 检查账号是否拥有指定权限(返回布尔值)

func HasRole

func HasRole(loginID interface{}, role string) bool

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 IsLogin

func IsLogin(tokenValue string) bool

IsLogin checks if the user is logged in | 检查用户是否已登录

func Kickout

func Kickout(loginID interface{}, device ...string) error

Kickout kicks out a user session | 踢人下线

func Login

func Login(loginID interface{}, device ...string) (string, error)

Login performs user login | 用户登录

func LoginByToken

func LoginByToken(loginID interface{}, tokenValue string, device ...string) error

LoginByToken performs login with specified token | 使用指定Token登录

func Logout

func Logout(loginID interface{}, device ...string) error

Logout performs user logout | 用户登出

func LogoutByToken

func LogoutByToken(tokenValue string) error

LogoutByToken performs logout by token | 根据Token登出

func NewEchoContext

func NewEchoContext(c echo.Context) adapter.RequestContext

NewEchoContext creates an Echo context adapter | 创建Echo上下文适配器

func RevokeRefreshToken

func RevokeRefreshToken(refreshToken string) error

RevokeRefreshToken revokes a refresh token | 撤销刷新令牌

func SetManager

func SetManager(mgr *Manager)

SetManager sets the global Manager (must be called first) | 设置全局Manager(必须先调用此方法)

func Untie

func Untie(loginID interface{}) error

Untie unties/unlocks an account | 解除账号封禁

func VerifyNonce

func VerifyNonce(nonce string) bool

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

type Builder = core.Builder

Core types | 核心类型

func NewBuilder

func NewBuilder() *Builder

NewBuilder creates a new builder for fluent configuration | 创建新的Builder构建器(用于流式配置)

type Config

type Config = core.Config

Configuration related types | 配置相关类型

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default configuration | 返回默认配置

type CookieConfig

type CookieConfig = core.CookieConfig

Configuration related types | 配置相关类型

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 Event

type Event = core.Event

Event related types | 事件相关类型

type EventData

type EventData = core.EventData

Event related types | 事件相关类型

type EventListener

type EventListener = core.EventListener

Event related types | 事件相关类型

type EventManager

type EventManager = core.EventManager

Event related types | 事件相关类型

func NewEventManager

func NewEventManager() *EventManager

NewEventManager creates a new event manager | 创建新的事件管理器

type ListenerConfig

type ListenerConfig = core.ListenerConfig

Event related types | 事件相关类型

type ListenerFunc

type ListenerFunc = core.ListenerFunc

Event related types | 事件相关类型

type Manager

type Manager = core.Manager

Core types | 核心类型

func GetManager

func GetManager() *Manager

GetManager gets the global Manager | 获取全局Manager

func NewManager

func NewManager(storage Storage, cfg *Config) *Manager

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 OAuth2AccessToken

type OAuth2AccessToken = core.OAuth2AccessToken

Core types | 核心类型

type OAuth2Client

type OAuth2Client = core.OAuth2Client

Core types | 核心类型

type OAuth2GrantType

type OAuth2GrantType = core.OAuth2GrantType

Core types | 核心类型

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 NewPlugin

func NewPlugin(manager *core.Manager) *Plugin

NewPlugin creates an Echo plugin | 创建Echo插件

func (*Plugin) AuthMiddleware

func (p *Plugin) AuthMiddleware() echo.MiddlewareFunc

AuthMiddleware authentication middleware | 认证中间件

func (*Plugin) LoginHandler

func (p *Plugin) LoginHandler(c echo.Context) error

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 RequestContext

type RequestContext = core.RequestContext

Adapter interfaces | 适配器接口

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

type Session = core.Session

Core types | 核心类型

func GetSession

func GetSession(loginID interface{}) (*Session, error)

GetSession gets the session for a login ID | 获取登录ID的Session

func GetSessionByToken

func GetSessionByToken(tokenValue string) (*Session, error)

GetSessionByToken gets the session by token | 根据Token获取Session

func GetTokenSession

func GetTokenSession(tokenValue string) (*Session, error)

GetTokenSession gets the token session | 获取Token的Session

func LoadSession

func LoadSession(id string, storage Storage, prefix string) (*Session, error)

LoadSession loads an existing session | 加载已存在的Session

func NewSession

func NewSession(id string, storage Storage, prefix string) *Session

NewSession creates a new session | 创建新的Session

type Storage

type Storage = core.Storage

Adapter interfaces | 适配器接口

type TokenGenerator

type TokenGenerator = core.TokenGenerator

Core types | 核心类型

func NewTokenGenerator

func NewTokenGenerator(cfg *Config) *TokenGenerator

NewTokenGenerator creates a new token generator | 创建新的Token生成器

type TokenInfo

type TokenInfo = core.TokenInfo

Core types | 核心类型

func GetTokenInfo

func GetTokenInfo(tokenValue string) (*TokenInfo, error)

GetTokenInfo gets token information | 获取Token信息

type TokenStyle

type TokenStyle = core.TokenStyle

Configuration related types | 配置相关类型

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL