Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFileContent ¶
GetFileContent 从嵌入式文件系统中读取文件内容
func GetLoginHTMLContent ¶
GetLoginHTMLContent 获取登录页面的HTML内容
Types ¶
type Authenticator ¶
type Authenticator interface {
// Middleware 返回一个Gin中间件,用于处理认证
Middleware() gin.HandlerFunc
// AuthType 返回认证类型
AuthType() AuthType
// LoginPageEnabled 返回是否启用了登录页
LoginPageEnabled() bool
// GetCredentials 返回认证凭据
GetCredentials() (username, password string)
}
Authenticator 接口定义了认证器的方法
func NewAuthenticator ¶
func NewAuthenticator(config Config) Authenticator
NewAuthenticator 根据配置创建一个认证器
type BasicAuthenticator ¶
type BasicAuthenticator struct {
// contains filtered or unexported fields
}
BasicAuthenticator 实现了HTTP Basic认证
func NewBasicAuth ¶
func NewBasicAuth(config Config) *BasicAuthenticator
NewBasicAuth 创建一个BasicAuth认证器
func (*BasicAuthenticator) AuthType ¶
func (a *BasicAuthenticator) AuthType() AuthType
AuthType 返回认证类型
func (*BasicAuthenticator) GetCredentials ¶
func (a *BasicAuthenticator) GetCredentials() (username, password string)
GetCredentials 返回认证凭据
func (*BasicAuthenticator) LoginPageEnabled ¶
func (a *BasicAuthenticator) LoginPageEnabled() bool
LoginPageEnabled 返回是否启用了登录页
func (*BasicAuthenticator) Middleware ¶
func (a *BasicAuthenticator) Middleware() gin.HandlerFunc
Middleware 返回Gin的Basic认证中间件
type Config ¶
type Config struct {
// AuthType 认证类型
Type AuthType
// Username 用户名,用于BasicAuth和FormAuth
Username string
// Password 密码,用于BasicAuth和FormAuth
Password string
// Token 令牌,用于TokenAuth
Token string
// EnableLoginPage 是否启用登录页面
EnableLoginPage bool
// Realm 认证域,用于BasicAuth
Realm string
}
Config 保存认证配置
func (*Config) GetGlobalConfig ¶
GetGlobalConfig 获取全局配置
type FormAuthenticator ¶
type FormAuthenticator struct {
// contains filtered or unexported fields
}
FormAuthenticator 实现了基于表单的认证
func (*FormAuthenticator) AuthType ¶
func (a *FormAuthenticator) AuthType() AuthType
AuthType 返回认证类型
func (*FormAuthenticator) GetCredentials ¶
func (a *FormAuthenticator) GetCredentials() (username, password string)
GetCredentials 返回认证凭据
func (*FormAuthenticator) LoginPageEnabled ¶
func (a *FormAuthenticator) LoginPageEnabled() bool
LoginPageEnabled 返回是否启用了登录页
func (*FormAuthenticator) Middleware ¶
func (a *FormAuthenticator) Middleware() gin.HandlerFunc
Middleware 返回表单认证中间件
func (*FormAuthenticator) SetupRoutes ¶
func (a *FormAuthenticator) SetupRoutes(router *gin.Engine)
SetupRoutes 设置表单认证的路由
type LoginPageData ¶
type LoginPageData struct {
Lang string
Title string
Header string
Subheader string
UsernameLabel string
PasswordLabel string
ButtonText string
ErrorEmptyFields string
ErrorCredentials string
}
LoginPageData 登录页面的数据结构
type NoAuthenticator ¶
type NoAuthenticator struct{}
NoAuthenticator 实现了一个不进行认证的认证器
func (*NoAuthenticator) GetCredentials ¶
func (a *NoAuthenticator) GetCredentials() (username, password string)
GetCredentials 返回认证凭据
func (*NoAuthenticator) LoginPageEnabled ¶
func (a *NoAuthenticator) LoginPageEnabled() bool
LoginPageEnabled 返回是否启用了登录页
func (*NoAuthenticator) Middleware ¶
func (a *NoAuthenticator) Middleware() gin.HandlerFunc
Middleware 返回一个不进行认证的中间件
type TokenAuthenticator ¶
type TokenAuthenticator struct {
// contains filtered or unexported fields
}
TokenAuthenticator 实现了基于令牌的认证
func NewTokenAuth ¶
func NewTokenAuth(config Config) *TokenAuthenticator
NewTokenAuth 创建一个TokenAuth认证器
func (*TokenAuthenticator) AuthType ¶
func (a *TokenAuthenticator) AuthType() AuthType
AuthType 返回认证类型
func (*TokenAuthenticator) GetCredentials ¶
func (a *TokenAuthenticator) GetCredentials() (username, password string)
GetCredentials 返回认证凭据
func (*TokenAuthenticator) LoginPageEnabled ¶
func (a *TokenAuthenticator) LoginPageEnabled() bool
LoginPageEnabled 返回是否启用了登录页
func (*TokenAuthenticator) Middleware ¶
func (a *TokenAuthenticator) Middleware() gin.HandlerFunc
Middleware 返回一个检查令牌的中间件