Documentation
¶
Overview ¶
@Author daixk 2025/12/22 15:56:00
@Author daixk 2025/12/22 15:56:00
Index ¶
- Constants
- type ConcurrencyScope
- type Config
- func (c *Config) Clone() *Config
- func (c *Config) SetActiveTimeout(timeout int64) *Config
- func (c *Config) SetAsyncEvent(asyncEvent bool) *Config
- func (c *Config) SetAuthType(authType string) *Config
- func (c *Config) SetAutoRenew(autoRenew bool) *Config
- func (c *Config) SetCookieConfig(cookieConfig *CookieConfig) *Config
- func (c *Config) SetIsConcurrent(isConcurrent bool) *Config
- func (c *Config) SetIsLog(isLog bool) *Config
- func (c *Config) SetIsPrintBanner(isPrint bool) *Config
- func (c *Config) SetIsReadBody(isReadBody bool) *Config
- func (c *Config) SetIsReadCookie(isReadCookie bool) *Config
- func (c *Config) SetIsReadHeader(isReadHeader bool) *Config
- func (c *Config) SetIsShare(isShare bool) *Config
- func (c *Config) SetJwtSecretKey(key string) *Config
- func (c *Config) SetKeyPrefix(keyPrefix string) *Config
- func (c *Config) SetMaxLoginCount(count int64) *Config
- func (c *Config) SetOverflowLogoutMode(mode LogoutMode) *Config
- func (c *Config) SetRenewInterval(interval int64) *Config
- func (c *Config) SetRenewMaxRefresh(refresh int64) *Config
- func (c *Config) SetReplacedLoginExitMode(mode ReplacedLoginExitMode) *Config
- func (c *Config) SetTimeout(timeout int64) *Config
- func (c *Config) SetTokenName(name string) *Config
- func (c *Config) SetTokenStyle(style adapter.TokenStyle) *Config
- func (c *Config) Validate() error
- type CookieConfig
- type LogoutMode
- type ReplacedLoginExitMode
- type SameSiteMode
Constants ¶
const ( // DefaultTokenName stores default token name DefaultTokenName 存储默认 Token 名称 DefaultTokenName = "dtoken" // DefaultKeyPrefix stores default key prefix DefaultKeyPrefix 存储默认存储键前缀 DefaultKeyPrefix = "dtoken:" // DefaultAuthType stores default auth type DefaultAuthType 存储默认认证体系类型 DefaultAuthType = "auth:" // TokenKeyPrefix stores token key prefix TokenKeyPrefix 存储 Token 键前缀 TokenKeyPrefix = "token:" // DefaultTimeout stores default timeout DefaultTimeout 存储默认 Token 超时时间 DefaultTimeout = 2592000 // DefaultJWTSecretKey stores default jwt secret key DefaultJWTSecretKey 存储默认 JWT 密钥 DefaultJWTSecretKey = "dtoken-go" // DefaultMaxLoginCount stores default max login count DefaultMaxLoginCount 存储默认最大并发登录数 DefaultMaxLoginCount = 12 // DefaultCookiePath stores default cookie path DefaultCookiePath 存储默认 Cookie 路径 DefaultCookiePath = "/" // NoLimit marks unlimited value NoLimit 标记无限制取值 NoLimit = -1 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrencyScope ¶
type ConcurrencyScope string
ConcurrencyScope defines concurrency scope ConcurrencyScope 定义并发控制作用域
const ( // ConcurrencyScopeAccount uses account scope ConcurrencyScopeAccount 使用账号级别作用域 ConcurrencyScopeAccount ConcurrencyScope = "account" // ConcurrencyScopeDevice uses device scope ConcurrencyScopeDevice 使用设备级别作用域 ConcurrencyScopeDevice ConcurrencyScope = "device" )
type Config ¶
type Config struct {
// AuthType stores auth type AuthType 存储认证体系类型
AuthType string
// KeyPrefix stores storage key prefix KeyPrefix 存储存储键前缀
KeyPrefix string
// TokenName stores token name TokenName 存储 Token 名称
TokenName string
// Timeout stores token timeout seconds Timeout 存储 Token 超时时间秒数
Timeout int64
// AutoRenew controls auto renew AutoRenew 控制是否在校验时自动续期
AutoRenew bool
// RenewMaxRefresh stores renew trigger threshold RenewMaxRefresh 存储自动续期触发阈值
RenewMaxRefresh int64
// RenewInterval stores minimum renew interval RenewInterval 存储同一 Token 的最小续期间隔
RenewInterval int64
// ActiveTimeout stores max inactive duration ActiveTimeout 存储最大不活跃时长
ActiveTimeout int64
// ConcurrencyScope stores concurrency scope ConcurrencyScope 存储并发控制作用域
ConcurrencyScope ConcurrencyScope
// IsConcurrent controls concurrent login IsConcurrent 控制是否允许同一账号并发登录
IsConcurrent bool
IsShare bool
// MaxLoginCount stores max login count MaxLoginCount 存储同一账号最大登录数量
MaxLoginCount int64
// ReplacedLoginExitMode stores non-concurrent strategy ReplacedLoginExitMode 存储非并发登录处理策略
ReplacedLoginExitMode ReplacedLoginExitMode
// OverflowLogoutMode stores max-login overflow mode OverflowLogoutMode 存储最大登录数溢出处理模式
OverflowLogoutMode LogoutMode
// IsReadBody controls body token read IsReadBody 控制是否尝试从请求体读取 Token
IsReadBody bool
// IsReadHeader controls header token read IsReadHeader 控制是否尝试从 HTTP Header 读取 Token
IsReadHeader bool
// IsReadCookie controls cookie token read IsReadCookie 控制是否尝试从 Cookie 读取 Token
IsReadCookie bool
// TokenStyle stores token style TokenStyle 存储 Token 生成风格
TokenStyle adapter.TokenStyle
// JwtSecretKey stores JWT secret JwtSecretKey 存储 JWT 模式密钥
JwtSecretKey string
// IsLog controls logging IsLog 控制是否开启操作日志
IsLog bool
// IsPrintBanner controls banner print IsPrintBanner 控制是否打印启动 Banner
IsPrintBanner bool
// AsyncEvent controls async event AsyncEvent 控制是否异步触发事件
AsyncEvent bool
// CookieConfig stores cookie config CookieConfig 存储 Cookie 配置
CookieConfig *CookieConfig
}
Config defines runtime config Config 定义运行时配置
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns default config DefaultConfig 返回默认配置
func (*Config) SetActiveTimeout ¶
SetActiveTimeout sets active timeout SetActiveTimeout 设置最大不活跃时长
func (*Config) SetAsyncEvent ¶
SetAsyncEvent sets async event switch SetAsyncEvent 设置是否异步触发事件
func (*Config) SetAuthType ¶
SetAuthType sets auth type SetAuthType 设置认证体系类型
func (*Config) SetAutoRenew ¶
SetAutoRenew sets auto renew switch SetAutoRenew 设置是否自动续期
func (*Config) SetCookieConfig ¶
func (c *Config) SetCookieConfig(cookieConfig *CookieConfig) *Config
SetCookieConfig sets cookie config SetCookieConfig 设置 Cookie 配置
func (*Config) SetIsConcurrent ¶
SetIsConcurrent sets concurrent switch SetIsConcurrent 设置是否允许并发登录
func (*Config) SetIsPrintBanner ¶
SetIsPrintBanner sets banner print switch SetIsPrintBanner 设置是否打印启动 Banner
func (*Config) SetIsReadBody ¶
SetIsReadBody sets body read switch SetIsReadBody 设置是否从请求体读取 Token
func (*Config) SetIsReadCookie ¶
SetIsReadCookie sets cookie read switch SetIsReadCookie 设置是否从 Cookie 读取 Token
func (*Config) SetIsReadHeader ¶
SetIsReadHeader sets header read switch SetIsReadHeader 设置是否从 Header 读取 Token
func (*Config) SetIsShare ¶
SetIsShare sets share switch SetIsShare 设置是否共享 Token
func (*Config) SetJwtSecretKey ¶
SetJwtSecretKey sets JWT secret SetJwtSecretKey 设置 JWT 密钥
func (*Config) SetKeyPrefix ¶
SetKeyPrefix sets key prefix SetKeyPrefix 设置存储键前缀
func (*Config) SetMaxLoginCount ¶
SetMaxLoginCount sets max login count SetMaxLoginCount 设置最大登录数量
func (*Config) SetOverflowLogoutMode ¶
func (c *Config) SetOverflowLogoutMode(mode LogoutMode) *Config
SetOverflowLogoutMode sets overflow logout mode SetOverflowLogoutMode 设置超限登录下线模式
func (*Config) SetRenewInterval ¶
SetRenewInterval sets renew interval SetRenewInterval 设置最小续期间隔
func (*Config) SetRenewMaxRefresh ¶
SetRenewMaxRefresh sets renew threshold SetRenewMaxRefresh 设置自动续期触发阈值
func (*Config) SetReplacedLoginExitMode ¶
func (c *Config) SetReplacedLoginExitMode(mode ReplacedLoginExitMode) *Config
SetReplacedLoginExitMode sets replaced login strategy SetReplacedLoginExitMode 设置非并发登录处理策略
func (*Config) SetTimeout ¶
SetTimeout sets timeout SetTimeout 设置超时时间
func (*Config) SetTokenName ¶
SetTokenName sets token name SetTokenName 设置 Token 名称
func (*Config) SetTokenStyle ¶
func (c *Config) SetTokenStyle(style adapter.TokenStyle) *Config
SetTokenStyle sets token style SetTokenStyle 设置 Token 生成风格
type CookieConfig ¶
type CookieConfig struct {
// Domain stores cookie domain Domain 存储 Cookie 作用域
Domain string
// Path stores cookie path Path 存储 Cookie 路径
Path string
// Secure controls HTTPS only Secure 控制是否仅在 HTTPS 下生效
Secure bool
// HttpOnly controls JavaScript access HttpOnly 控制是否禁止 JavaScript 访问 Cookie
HttpOnly bool
// SameSite stores sameSite mode SameSite 存储 SameSite 属性
SameSite SameSiteMode
// MaxAge stores cookie max age seconds MaxAge 存储 Cookie 过期时间秒数
MaxAge int64
}
CookieConfig defines cookie config CookieConfig 定义 Cookie 配置结构体
func DefaultCookieConfig ¶
func DefaultCookieConfig() *CookieConfig
DefaultCookieConfig returns default cookie config DefaultCookieConfig 返回默认 Cookie 配置
type LogoutMode ¶
type LogoutMode string
LogoutMode defines token exit mode LogoutMode 定义 Token 下线模式
const ( // LogoutModeLogout deletes token mapping LogoutModeLogout 删除 Token 映射 LogoutModeLogout LogoutMode = "logout" // LogoutModeKickout marks token as kicked out LogoutModeKickout 标记 Token 被踢下线 LogoutModeKickout LogoutMode = "kickout" // LogoutModeReplaced marks token as replaced LogoutModeReplaced 标记 Token 被顶下线 LogoutModeReplaced LogoutMode = "replaced" )
type ReplacedLoginExitMode ¶
type ReplacedLoginExitMode string
ReplacedLoginExitMode defines non-concurrent login strategy ReplacedLoginExitMode 定义非并发登录处理策略
const ( // ReplacedLoginExitModeOldDevice exits old terminals ReplacedLoginExitModeOldDevice 让旧终端下线 ReplacedLoginExitModeOldDevice ReplacedLoginExitMode = "old_device" // ReplacedLoginExitModeNewDevice rejects new login ReplacedLoginExitModeNewDevice 拒绝新终端登录 ReplacedLoginExitModeNewDevice ReplacedLoginExitMode = "new_device" )
type SameSiteMode ¶
type SameSiteMode string
SameSiteMode defines cookie sameSite mode SameSiteMode 定义 Cookie SameSite 属性值
const ( // SameSiteStrict uses strict mode SameSiteStrict 使用严格模式 SameSiteStrict SameSiteMode = "Strict" // SameSiteLax uses lax mode SameSiteLax 使用宽松模式 SameSiteLax SameSiteMode = "Lax" // SameSiteNone uses none mode SameSiteNone 使用无限制模式 SameSiteNone SameSiteMode = "None" )