Documentation
¶
Index ¶
- Constants
- type Config
- func (c *Config) Clone() *Config
- func (c *Config) SetActiveTimeout(timeout int64) *Config
- func (c *Config) SetAutoRenew(autoRenew bool) *Config
- func (c *Config) SetCookieConfig(cookieConfig *CookieConfig) *Config
- func (c *Config) SetDataRefreshPeriod(period int64) *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(prefix string) *Config
- func (c *Config) SetMaxLoginCount(count int) *Config
- func (c *Config) SetRenewPoolConfig(renewPoolConfig *pool.RenewPoolConfig) *Config
- func (c *Config) SetTimeout(timeout int64) *Config
- func (c *Config) SetTokenName(name string) *Config
- func (c *Config) SetTokenSessionCheckLogin(check bool) *Config
- func (c *Config) SetTokenStyle(style TokenStyle) *Config
- func (c *Config) Validate() error
- type CookieConfig
- type SameSiteMode
- type TokenStyle
Constants ¶
const ( // 默认 Token 名称沿用 Java 版 "sa-token",便于跨端配置一致性 DefaultTokenName = "sa-token" DefaultTimeout = 2592000 // 30 days in seconds | 30天(秒) DefaultMaxLoginCount = 12 // Maximum concurrent logins | 最大并发登录数 DefaultCookiePath = "/" NoLimit = -1 // No limit flag | 不限制标志 )
Default configuration constants | 默认配置常量
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// TokenName Token name (also used as Cookie name) | Token名称(同时也是Cookie名称)
TokenName string
// Timeout Token expiration time in seconds, -1 for never expire | Token超时时间(单位:秒,-1代表永不过期)
Timeout int64
// ActiveTimeout Token minimum activity frequency in seconds. If Token is not accessed for this time, it will be frozen. -1 means no limit | Token最低活跃频率(单位:秒),如果Token超过此时间没有访问,则会被冻结。-1代表不限制,永不冻结
ActiveTimeout int64
// IsConcurrent Allow concurrent login for the same account (true=allow concurrent login, false=new login kicks out old login) | 是否允许同一账号并发登录(为true时允许一起登录,为false时新登录挤掉旧登录)
IsConcurrent bool
IsShare bool
// MaxLoginCount Maximum number of concurrent logins for the same account, -1 means no limit (only effective when IsConcurrent=true and IsShare=false) | 同一账号最大登录数量,-1代表不限(只有在IsConcurrent=true,IsShare=false时此配置才有效)
MaxLoginCount int
// IsReadBody Try to read Token from request body (default: false) | 是否尝试从请求体里读取Token(默认:false)
IsReadBody bool
// IsReadHeader Try to read Token from HTTP Header (default: true, recommended) | 是否尝试从Header里读取Token(默认:true,推荐)
IsReadHeader bool
// IsReadCookie Try to read Token from Cookie (default: false) | 是否尝试从Cookie里读取Token(默认:false)
IsReadCookie bool
// TokenStyle Token generation style | Token风格
TokenStyle TokenStyle
// DataRefreshPeriod Auto-refresh period in seconds, -1 means no auto-refresh | 自动续签(单位:秒),-1代表不自动续签
DataRefreshPeriod int64
// TokenSessionCheckLogin Check if Token-Session is kicked out when logging in (true=check on login, false=skip check) | Token-Session在登录时是否检查(true=登录时验证是否被踢下线,false=不作此检查)
TokenSessionCheckLogin bool
// AutoRenew Auto-renew Token expiration time on each validation | 是否自动续期(每次验证Token时,都会延长Token的有效期)
AutoRenew bool
// JwtSecretKey JWT secret key (only effective when TokenStyle=JWT) | JWT密钥(只有TokenStyle=JWT时,此配置才生效)
JwtSecretKey string
// JwtAlgorithm JWT 签名算法,可选 HS256/HS384/HS512/RS256/RS384/RS512,默认 HS256
JwtAlgorithm string
// JwtPrivateKey RSA 私钥(PEM),当算法为 RS* 时必填
JwtPrivateKey string
// JwtPublicKey RSA 公钥(PEM),当算法为 RS* 时验签使用,可选;为空则使用私钥推导
JwtPublicKey string
// JwtKeyID 写入 header.kid,便于密钥识别,可选
JwtKeyID string
// JwtCustomClaims 追加的自定义声明 | 自定义声明
JwtCustomClaims map[string]string
// IsLog Enable operation logging | 是否输出操作日志
IsLog bool
// IsPrintBanner Print startup banner (default: true) | 是否打印启动 Banner(默认:true)
IsPrintBanner bool
// KeyPrefix Storage key prefix for Redis isolation (default: "satoken:") | 存储键前缀,用于Redis隔离(默认:"satoken:")
// Set to empty "" to be compatible with Java sa-token default behavior | 设置为空""以兼容Java sa-token默认行为
KeyPrefix string
// CookieConfig Cookie configuration | Cookie配置
CookieConfig *CookieConfig
// RenewPoolConfig Configuration for renewal pool manager | 续期池配置
RenewPoolConfig *pool.RenewPoolConfig
}
Config Sa-Token configuration | Sa-Token配置
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig Returns default configuration | 返回默认配置
func (*Config) SetActiveTimeout ¶
SetActiveTimeout Set active timeout duration | 设置活跃超时时间
func (*Config) SetAutoRenew ¶
SetAutoRenew Set whether to auto-renew Token | 设置是否自动续期
func (*Config) SetCookieConfig ¶
func (c *Config) SetCookieConfig(cookieConfig *CookieConfig) *Config
SetCookieConfig Set cookie configuration | 设置Cookie配置
func (*Config) SetDataRefreshPeriod ¶
SetDataRefreshPeriod Set data refresh period | 设置数据刷新周期
func (*Config) SetIsConcurrent ¶
SetIsConcurrent Set whether to allow concurrent login | 设置是否允许并发登录
func (*Config) SetIsPrintBanner ¶
SetIsPrintBanner Set whether to print banner | 设置是否打印Banner
func (*Config) SetIsReadBody ¶
SetIsReadBody Set whether to read Token from body | 设置是否从请求体读取Token
func (*Config) SetIsReadCookie ¶
SetIsReadCookie Set whether to read Token from cookie | 设置是否从Cookie读取Token
func (*Config) SetIsReadHeader ¶
SetIsReadHeader Set whether to read Token from header | 设置是否从Header读取Token
func (*Config) SetIsShare ¶
SetIsShare Set whether to share Token | 设置是否共享Token
func (*Config) SetJwtSecretKey ¶
SetJwtSecretKey Set JWT secret key | 设置JWT密钥
func (*Config) SetKeyPrefix ¶
SetKeyPrefix Set storage key prefix | 设置存储键前缀
func (*Config) SetMaxLoginCount ¶
SetMaxLoginCount Set maximum login count | 设置最大登录数量
func (*Config) SetRenewPoolConfig ¶
func (c *Config) SetRenewPoolConfig(renewPoolConfig *pool.RenewPoolConfig) *Config
SetRenewPoolConfig Set renewal pool configuration | 设置续期池配置
func (*Config) SetTimeout ¶
SetTimeout Set timeout duration | 设置超时时间
func (*Config) SetTokenName ¶
SetTokenName Set Token name | 设置Token名称
func (*Config) SetTokenSessionCheckLogin ¶
SetTokenSessionCheckLogin Set whether to check token session on login | 设置登录时是否检查token会话
func (*Config) SetTokenStyle ¶
func (c *Config) SetTokenStyle(style TokenStyle) *Config
SetTokenStyle Set Token generation style | 设置Token风格
type CookieConfig ¶
type CookieConfig struct {
// Domain Cookie domain | 作用域
Domain string
// Path Cookie path | 路径
Path string
// Secure Only effective under HTTPS | 是否只在HTTPS下生效
Secure bool
// HttpOnly Prevent JavaScript access to Cookie | 是否禁止JS操作Cookie
HttpOnly bool
// SameSite SameSite attribute (Strict, Lax, None) | SameSite属性(Strict、Lax、None)
SameSite SameSiteMode
// MaxAge Cookie expiration time in seconds | 过期时间(单位:秒)
MaxAge int
}
CookieConfig Cookie configuration | Cookie配置
type SameSiteMode ¶
type SameSiteMode string
SameSiteMode Cookie SameSite attribute values | Cookie的SameSite属性值
const ( // SameSiteStrict Strict mode | 严格模式 SameSiteStrict SameSiteMode = "Strict" // SameSiteLax Lax mode | 宽松模式 SameSiteLax SameSiteMode = "Lax" // SameSiteNone None mode | 无限制模式 SameSiteNone SameSiteMode = "None" )
type TokenStyle ¶
type TokenStyle string
TokenStyle Token generation style | Token生成风格
const ( // TokenStyleUUID UUID style | UUID风格 TokenStyleUUID TokenStyle = "uuid" // TokenStyleSimple Simple random string | 简单随机字符串 TokenStyleSimple TokenStyle = "simple" // TokenStyleRandom32 32-bit random string | 32位随机字符串 TokenStyleRandom32 TokenStyle = "random32" // TokenStyleRandom64 64-bit random string | 64位随机字符串 TokenStyleRandom64 TokenStyle = "random64" // TokenStyleRandom128 128-bit random string | 128位随机字符串 TokenStyleRandom128 TokenStyle = "random128" // TokenStyleJWT JWT style | JWT风格 TokenStyleJWT TokenStyle = "jwt" // TokenStyleHash SHA256 hash-based style | SHA256哈希风格 TokenStyleHash TokenStyle = "hash" // TokenStyleTimestamp Timestamp-based style | 时间戳风格 TokenStyleTimestamp TokenStyle = "timestamp" // TokenStyleTik Short ID style (like TikTok) | Tik风格短ID(类似抖音) TokenStyleTik TokenStyle = "tik" )
func (TokenStyle) IsValid ¶
func (ts TokenStyle) IsValid() bool
IsValid checks if the TokenStyle is valid | 检查TokenStyle是否有效