utils

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultJWTConfig = &JWTConfig{
	SecretKey:      "",
	ExpirationTime: 24 * time.Hour,
}

DefaultJWTConfig 默认JWT配置

View Source
var DefaultPasswordConfig = &PasswordConfig{
	Time:    1,
	Memory:  64 * 1024,
	Threads: 4,
	KeyLen:  32,
}

DefaultPasswordConfig 默认密码配置

Functions

func Dial

func Dial(dial *config.Dial, index int) (net.Conn, error)

func GenerateRandomPassword

func GenerateRandomPassword(length int) (string, error)

GenerateRandomPassword 生成随机密码

func GenerateToken

func GenerateToken(userID uint, email string) (string, error)

GenerateToken 生成JWT token

func HashPassword

func HashPassword(password string) (string, error)

HashPassword 加密密码

func IsLinuxPhysicalInterface

func IsLinuxPhysicalInterface(iface *net.Interface) bool

IsLinuxPhysicalInterface Linux 专用的物理接口判断 只做基本过滤,不使用 sysfs 检查(适用于容器环境)

func IsLocallyAdministeredMAC

func IsLocallyAdministeredMAC(mac string) bool

IsLocallyAdministeredMAC 判断 MAC 地址是否是本地管理的 本地管理的 MAC 地址的第 2 位为 1

func IsMacPhysicalInterface

func IsMacPhysicalInterface(iface *net.Interface) bool

IsMacPhysicalInterface macOS 专用的物理接口判断 注意:不检查 MAC 是否是本地管理的,即使 MAC 是本地管理的也会被获取(用于指纹生成)

func IsValidMAC

func IsValidMAC(mac string) bool

IsValidMAC 判断是否是有效的 MAC 地址

func IsWindowsPhysicalInterface

func IsWindowsPhysicalInterface(iface *net.Interface) bool

IsWindowsPhysicalInterface Windows 专用的物理接口判断

func Listen

func Listen(listen *config.Listen) (net.Listener, error)

func NormalizeMAC

func NormalizeMAC(mac string) string

NormalizeMAC 标准化 MAC 地址(去除分隔符,转为小写)

func RefreshToken

func RefreshToken(tokenString string) (string, error)

RefreshToken 刷新token

func SetJWTSecret

func SetJWTSecret(secret string) error

SetJWTSecret 设置JWT密钥(用于从配置文件读取) 如果secret为空,将返回错误

func SetRLimit

func SetRLimit(fileLimit uint64) error

func VerifyPassword

func VerifyPassword(password, encodedHash string) (bool, error)

VerifyPassword 验证密码

Types

type Claims

type Claims struct {
	UserID uint   `json:"user_id"`
	Email  string `json:"email"`
	jwt.RegisteredClaims
}

Claims JWT声明

func ValidateToken

func ValidateToken(tokenString string) (*Claims, error)

ValidateToken 验证JWT token

type FingerprintComponents

type FingerprintComponents struct {
	MACs    []string
	CPUInfo string
	DiskIDs []string
	Raw     string
}

FingerprintComponents 指纹组成信息

func GetFingerprint

func GetFingerprint() (string, *FingerprintComponents, error)

GetFingerprint 获取设备指纹 基于 MAC、CPU、磁盘序列号生成指纹 所有组件都进行排序,确保指纹稳定性 返回指纹字符串、组成信息和错误

type JWTConfig

type JWTConfig struct {
	SecretKey      string
	ExpirationTime time.Duration
}

JWTConfig JWT配置

type PasswordConfig

type PasswordConfig struct {
	Time    uint32
	Memory  uint32
	Threads uint8
	KeyLen  uint32
}

PasswordConfig 密码配置

type WindowsNetworkAdapter

type WindowsNetworkAdapter struct {
	Name            string
	Description     string
	MACAddress      *string
	PhysicalAdapter bool
	NetEnabled      *bool
	Manufacturer    *string
}

WindowsNetworkAdapter Windows 网络适配器信息(通过 WMI 获取)

Jump to

Keyboard shortcuts

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