utils

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Captcha = captchaType{}
View Source
var Ctx = ctxType{}
View Source
var Email = emailType{}
View Source
var Password = PasswordType{}
View Source
var Random = randomType{}
View Source
var Token = TokenType{}

Functions

func ContainsToken

func ContainsToken(records []string, token string) bool

ContainsToken 检查TXT记录中是否包含指定令牌

func FileHash

func FileHash(filePath string) (string, error)

FileHash 计算文件的哈希值并返回十六进制字符串

func FileHashFromStream

func FileHashFromStream(file multipart.File) (string, error)

func FilePath

func FilePath(hash string) (dir, file string)

FilePath 根据哈希值生成文件路径,前4位为目录位hash[0:4]/hash

func GenerateRandomString

func GenerateRandomString(length int) string

GenerateRandomString 生成随机字符串

func GetEnv

func GetEnv(key string, defaultValue string) string

func GetEnvBool

func GetEnvBool(key string, defaultValue bool) bool

func GetEnvInt

func GetEnvInt(key string, defaultValue int) int

func GetJsonFieldFromCtx

func GetJsonFieldFromCtx(c *app.RequestContext, path string) (string, bool)

GetJsonFieldFromCtx 高效获取JSON字段

func IsValidEntityName

func IsValidEntityName(name string) bool

IsValidEntityName 检查字符串是否符合Git仓库命名规范,该函数只应被检查owner和project,site的方法所调用,不能被其他地方调用

func IsValidZipFile

func IsValidZipFile(fileHeader *multipart.FileHeader) (bool, error)

IsValidZipFile 检查 multipart.FileHeader 是否为合法的 ZIP 文件

func LookupTXTRecords

func LookupTXTRecords(domain string) ([]string, error)

LookupTXTRecords 查询域名的TXT记录

func NormalizeDomain

func NormalizeDomain(domain string) string

NormalizeDomain 规范化域名,确保格式正确

func RunWithMode

func RunWithMode(h *server.Hertz, mode string) error

func SendEmail

func SendEmail(ctx context.Context, emailConfig *EmailConfig, target, subject, content string, isHTML bool) error

SendEmail 使用gomail库发送邮件

func SendTemplate

func SendTemplate(ctx context.Context, emailConfig *EmailConfig, target, subject, htmlTemplate string, data map[string]interface{}) error

SendTemplate 发送HTML模板,从配置文件中读取邮箱配置,支持上下文控制

func VerifyDomainOwnership

func VerifyDomainOwnership(domain, token string) (bool, error)

VerifyDomainOwnership 验证域名所有权

Types

type CaptchaConfig

type CaptchaConfig struct {
	Type        string
	SiteSecrete string
	SecretKey   string
}

type Claims

type Claims struct {
	jwt.RegisteredClaims
	UserID   uint `json:"user_id"`  // 用户ID,用于身份验证
	TokenID  uint `json:"token_id"` // 令牌ID,用于服务端会话维持
	Stateful bool `json:"stateful"` // 是否为有状态Token
}

type EmailConfig

type EmailConfig struct {
	Enable   bool   // 邮箱启用状态
	Username string // 邮箱用户名
	Address  string // 邮箱地址
	Host     string // 邮箱服务器地址
	Port     string // 邮箱服务器端口
	Password string // 邮箱密码
	SSL      bool   // 是否使用SSL
}

type KVStore

type KVStore struct {
	// contains filtered or unexported fields
}

KVStore 是一个简单的内存键值存储系统

func GetKVStore

func GetKVStore() *KVStore

GetKVStore 获取KVStore单例实例

func (*KVStore) Clear

func (s *KVStore) Clear()

Clear 清空所有键值对

func (*KVStore) Delete

func (s *KVStore) Delete(key string)

Delete 删除键值对

func (*KVStore) Get

func (s *KVStore) Get(key string) (interface{}, bool)

Get 获取键对应的值,如果键不存在或已过期则返回(nil, false)

func (*KVStore) Set

func (s *KVStore) Set(key string, value interface{}, ttl time.Duration)

Set 设置键值对,可选指定过期时间

type PasswordType

type PasswordType struct {
}

func (*PasswordType) CheckPasswordComplexity

func (u *PasswordType) CheckPasswordComplexity(password string, level int) bool

CheckPasswordComplexity 根据指定级别检查密码复杂度 password: 待检查的密码 level: 复杂度级别(1-4) 返回值: 是否满足复杂度要求

func (*PasswordType) HashPassword

func (u *PasswordType) HashPassword(password string, salt string) (string, error)

HashPassword 密码哈希函数

func (*PasswordType) VerifyPassword

func (u *PasswordType) VerifyPassword(password, hashedPassword string, salt string) bool

VerifyPassword 验证密码

type TokenType

type TokenType struct{}

func (TokenType) CreateApiToken

func (TokenType) CreateApiToken(userID uint, duration time.Duration, persistentHandler func(*models.ApiToken) error) (string, error)

CreateApiToken 生成API令牌

func (TokenType) CreateJsonWebToken

func (TokenType) CreateJsonWebToken(userID uint, duration time.Duration, stateful bool, persistentHandler func(uint) (*models.JsonWebToken, error)) (string, error)

CreateJsonWebToken 生成用户会话令牌(默认24小时有效)

func (TokenType) ParseApiToken

func (TokenType) ParseApiToken(tokenString string, isValidFunc func(string) (*models.ApiToken, error)) (*models.ApiToken, error)

ParseApiToken 解析API令牌

func (TokenType) ParseJsonWebToken

func (TokenType) ParseJsonWebToken(tokenString string, revokeChecker func(uint) bool) (*Claims, error)

ParseJsonWebToken 解析JWT令牌

type Utils

type Utils struct{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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