data

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 125 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogSettingAutoClear = "AutoClear" // 是否自动清理日志
	LogSettingClearDays = "ClearDays" // 清理天数
)

日志设置配置键(复刻原项目:updateLogSettingLogic.go) ⚠️ 注意:key名称必须与原项目保持一致(使用PascalCase,字段名即key)

View Source
const (
	LogTypeLogin    int8 = 30
	LogTypeRegister int8 = 31

	DefaultJWTSecret = "your-secret-key-change-in-production"
	DefaultJWTExpire = 604800
)
View Source
const (
	// StatusCacheKey 服务器状态缓存键格式
	StatusCacheKey = "node:status:%d"
	// OnlineUserCacheKeyWithSubscribe 在线用户订阅缓存键格式
	OnlineUserCacheKeyWithSubscribe = "node:online:subscribe:%d:%s"
	// OnlineUserSubscribeCacheKeyWithGlobal 全局在线订阅缓存键
	OnlineUserSubscribeCacheKeyWithGlobal = "node:online:subscribe:global"
	// CacheExpiry 缓存过期时间(秒)
	CacheExpiry = 300

	// Legacy auth/common cache keys must stay byte-for-byte compatible with the
	// old project because verification flows and rate limits are shared.
	AuthCodeCacheKey          = "auth:verify:email"
	AuthCodeTelephoneCacheKey = "auth:verify:telephone"
	SendIntervalKeyPrefix     = "send:interval:"
	SendCountLimitKeyPrefix   = "send:limit:"
	RegisterIpKeyPrefix       = "register:ip:"

	// System config cache keys
	CurrencyConfigKey   = "system:currency_config"
	InviteConfigKey     = "system:invite_config"
	NodeConfigKey       = "system:node_config"
	TosConfigKey        = "system:tos_config"
	RegisterConfigKey   = "system:register_config"
	SiteConfigKey       = "system:site_config"
	SubscribeConfigKey  = "system:subscribe_config"
	VerifyCodeConfigKey = "system:verify_code_config"
	VerifyConfigKey     = "system:verify_config"
	GlobalConfigKey     = "system:global_config"
	CommonStatCacheKey  = "common:stat"

	// Device admission control cache keys
	DeviceOnlineKeyPrefix     = "device:online:"  // + user_id
	DeviceSessionKeyPrefix    = "device:session:" // + user_id:identifier
	NodeSessionsKeyPrefix     = "node:sessions:"  // + server_id
	DeviceCountModeKey        = "system:device_count_mode"
	DeviceAdmissionEnabledKey = "system:device_admission_enabled"
)
View Source
const (
	// 支付方式常量
	Epay            = "epay"
	AlipayF2f       = "alipay_f2f"
	StripeAlipay    = "stripe_alipay"
	StripeWeChatPay = "stripe_wechat_pay"
	Balance         = "balance"

	// CloseOrderTimeMinutes 订单自动关闭的时间(分钟)
	CloseOrderTimeMinutes = 15

	// MaxQuantity 最大购买数量
	MaxQuantity = 1000

	// MaxOrderAmount 最大订单金额(分)
	MaxOrderAmount = 2147483647

	// MaxRechargeAmount 最大充值金额(分)
	MaxRechargeAmount = 2000000000
)

Variables

ProviderSet is data providers

Functions

func ClearLegacyServerAllCaches

func ClearLegacyServerAllCaches(ctx context.Context, rdb *redis.Client) error

func ClearLegacyServerCachesByServerIDs

func ClearLegacyServerCachesByServerIDs(ctx context.Context, rdb *redis.Client, serverIDs []int64) error

func GetGlobalDeviceManager

func GetGlobalDeviceManager() *device.DeviceManager

GetGlobalDeviceManager 获取全局设备管理器

func LegacyServerConfigCacheKey

func LegacyServerConfigCacheKey(serverID int64, protocol string) string

func LegacyServerUserListCacheKey

func LegacyServerUserListCacheKey(serverID int64) string

func LoadNodeConfigForServer

func LoadNodeConfigForServer(ctx context.Context, data *Data, logger log.Logger) (*systembiz.NodeConfig, error)

func NewAdminAnnouncementRepo

func NewAdminAnnouncementRepo(data *Data, logger log.Logger) announcementbiz.AnnouncementRepo

NewAdminAnnouncementRepo 创建公告数据仓库

func NewAdminAuthMethodRepo

func NewAdminAuthMethodRepo(data *Data, logger log.Logger) authmethodbiz.AuthMethodRepo

NewAdminAuthMethodRepo 创建认证方法仓储

func NewAdminConsoleRepo

func NewAdminConsoleRepo(data *Data, logger log.Logger) v1.ConsoleRepo

NewAdminConsoleRepo creates a new admin console repository

func NewAdminDocumentRepo

func NewAdminDocumentRepo(data *Data, logger log.Logger) documentbiz.DocumentRepo

NewAdminDocumentRepo 创建管理员文档仓库

func NewAdminGroupRepo

func NewAdminGroupRepo(d *Data, logger log.Logger) groupbiz.GroupRepo

NewAdminGroupRepo creates a new admin group repository

func NewAdminLogSettingRepo

func NewAdminLogSettingRepo(data *Data, logger log.Logger) logbiz.LogSettingRepo

NewAdminLogSettingRepo 创建日志设置仓库

func NewAdminMarketingRepo

func NewAdminMarketingRepo(data *Data, logger log.Logger) marketingbiz.MarketingRepo

NewAdminMarketingRepo 创建营销仓库

func NewAdminMigrationRepo

func NewAdminMigrationRepo(data *Data, logger log.Logger) serverbiz.MigrationRepo

NewAdminMigrationRepo creates a new admin migration repository

func NewAdminNodeRepo

func NewAdminNodeRepo(data *Data, logger log.Logger) serverbiz.NodeRepo

func NewAdminPaymentRepo

func NewAdminPaymentRepo(data *Data, logger log.Logger) paymentbiz.PaymentRepo

func NewAdminRedemptionRepo

func NewAdminRedemptionRepo(d *Data, logger log.Logger) redemptionbiz.RedemptionRepo

func NewAdminServerRepo

func NewAdminServerRepo(data *Data, logger log.Logger) serverbiz.ServerRepo

func NewAdminSystemLogRepo

func NewAdminSystemLogRepo(data *Data, logger log.Logger) logbiz.SystemLogRepo

NewAdminSystemLogRepo 创建系统日志仓库

func NewAdminSystemRepo

func NewAdminSystemRepo(data *Data, logger log.Logger) systembiz.SystemRepo

NewAdminSystemRepo creates a new admin system repository

func NewAdminTrafficLogRepo

func NewAdminTrafficLogRepo(data *Data, logger log.Logger) logbiz.TrafficLogRepo

NewAdminTrafficLogRepo 创建流量日志仓库

func NewAdminUserAuthMethodRepo

func NewAdminUserAuthMethodRepo(d *Data, logger log.Logger) userbiz.AuthMethodRepo

NewAdminUserAuthMethodRepo creates a new admin user auth method repository

func NewAdminUserDeviceRepo

func NewAdminUserDeviceRepo(d *Data, logger log.Logger) userbiz.DeviceRepo

NewAdminUserDeviceRepo creates a new admin user device repository

func NewAdminUserRepo

func NewAdminUserRepo(data *Data, logger log.Logger) userbiz.UserRepo

NewAdminUserRepo 创建用户数据仓库

func NewAdminUserSubscribeRepo

func NewAdminUserSubscribeRepo(d *Data, logger log.Logger) userbiz.SubscribeRepo

NewAdminUserSubscribeRepo creates a new admin user subscribe repository

func NewAdsRepo

func NewAdsRepo(data *Data, logger log.Logger) adsbiz.AdsRepo

NewAdsRepo 创建广告数据仓库

func NewAuthRepo

func NewAuthRepo(data *Data, config *conf.Application, logger log.Logger) authbiz.AuthRepo

func NewCommonRepo

func NewCommonRepo(data *Data, logger log.Logger) v1.CommonRepo

NewCommonRepo creates a new common repository

func NewCouponRepo

func NewCouponRepo(data *Data, logger log.Logger) coupon.CouponRepo

NewCouponRepo create coupon repository

func NewDeviceManager

func NewDeviceManager(d *Data) *device.DeviceManager

NewDeviceManager 提供设备管理器

func NewEntClient

func NewEntClient(d *Data) *ent.Client

NewEntClient 提供 ent.Client 给需要直接访问数据库的服务

func NewOAuthRepo

func NewOAuthRepo(d *Data, config *conf.Application, logger kratoLog.Logger) oauthBiz.OAuthRepo

NewOAuthRepo 创建OAuth仓储实例

func NewOrderRepo

func NewOrderRepo(data *Data, logger log.Logger) order.OrderRepo

NewOrderRepo create order repository

func NewPublicAnnouncementRepo

func NewPublicAnnouncementRepo(data *Data, logger log.Logger) announcementBiz.AnnouncementRepo

NewPublicAnnouncementRepo 创建Public Announcement仓库

func NewPublicDocumentRepo

func NewPublicDocumentRepo(data *Data, logger log.Logger) documentBiz.DocumentRepo

NewPublicDocumentRepo 创建Public Document仓库

func NewPublicOrderRepo

func NewPublicOrderRepo(data *Data, config *conf.Application, logger log.Logger) publicBiz.OrderRepo

NewPublicOrderRepo 创建公共订单仓储实例

func NewPublicPaymentRepo

func NewPublicPaymentRepo(data *Data, logger log.Logger) paymentBiz.PaymentRepo

NewPublicPaymentRepo 创建Public Payment仓库

func NewPublicPortalRepo

func NewPublicPortalRepo(d *Data, logger log.Logger) portalBiz.PortalRepo

NewPublicPortalRepo 创建Portal数据仓储实例

func NewPublicRedemptionRepo

func NewPublicRedemptionRepo(data *Data, logger log.Logger) redemptionBiz.RedemptionRepo

NewPublicRedemptionRepo 创建Public Redemption仓库

func NewPublicSubscribeRepo

func NewPublicSubscribeRepo(data *Data, logger log.Logger) subscribeBiz.SubscribeRepo

NewPublicSubscribeRepo 创建Public Subscribe仓库

func NewPublicSubscriptionRepo

func NewPublicSubscriptionRepo(data *Data, logger log.Logger) subscriptionbiz.SubscriptionRepo

NewPublicSubscriptionRepo 创建Public Subscription数据仓储实例

func NewPublicTicketRepo

func NewPublicTicketRepo(d *Data, logger log.Logger) ticketBiz.TicketRepo

NewPublicTicketRepo creates a new ticket repository

func NewPublicUserRepo

func NewPublicUserRepo(d *Data, logger kratoslog.Logger) userBiz.UserRepo

func NewServerNodeRepo

func NewServerNodeRepo(data *Data, logger log.Logger) serverBiz.ServerNodeRepo

NewServerNodeRepo 创建节点服务器数据仓储

func NewSubscribeApplicationRepo

func NewSubscribeApplicationRepo(data *Data, logger log.Logger) applicationbiz.SubscribeApplicationRepo

NewSubscribeApplicationRepo 创建订阅应用配置仓库

func NewSubscribeRepo

func NewSubscribeRepo(data *Data, logger log.Logger) subscribe.SubscribeRepo

NewSubscribeRepo create subscribe repository

func NewTicketRepo

func NewTicketRepo(data *Data, logger log.Logger) ticketbiz.TicketRepo

NewTicketRepo 创建工单仓库

func NewWithdrawalRepo

func NewWithdrawalRepo(data *Data, logger log.Logger) withdrawal.WithdrawalRepo

NewWithdrawalRepo 创建提现数据仓储

func UpdateOnlineUserSubscribeGlobalCache

func UpdateOnlineUserSubscribeGlobalCache(ctx context.Context, rdb redis.UniversalClient, subscribe OnlineUserSubscribe) error

Types

type AdminLoginParams

type AdminLoginParams struct {
	Email    string
	Password string
	Meta     authbiz.RequestMeta
}

type AdminResetPasswordParams

type AdminResetPasswordParams struct {
	Email    string
	Password string
	Code     string
	Meta     authbiz.RequestMeta
}

type AlipayF2FConfig

type AlipayF2FConfig struct {
	AppId       string `json:"app_id"`
	PrivateKey  string `json:"private_key"`
	PublicKey   string `json:"public_key"`
	InvoiceName string `json:"invoice_name"`
	Sandbox     bool   `json:"sandbox"`
}

AlipayF2FConfig 支付宝当面付配置

func (*AlipayF2FConfig) Unmarshal

func (c *AlipayF2FConfig) Unmarshal(data []byte) error

type AuthCompat

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

func NewAuthCompat

func NewAuthCompat(data *Data, config *conf.Application, logger log.Logger) *AuthCompat

func (*AuthCompat) AdminLogin

func (c *AuthCompat) AdminLogin(ctx context.Context, params *AdminLoginParams) (*authbiz.LoginResult, error)

func (*AuthCompat) AdminResetPassword

func (c *AuthCompat) AdminResetPassword(ctx context.Context, params *AdminResetPasswordParams) (*authbiz.LoginResult, error)

func (*AuthCompat) DeviceLogin

func (c *AuthCompat) DeviceLogin(ctx context.Context, params *DeviceLoginParams) (*authbiz.LoginResult, error)

func (*AuthCompat) GenerateCaptcha

func (c *AuthCompat) GenerateCaptcha(ctx context.Context) (*GenerateCaptchaResult, error)

func (*AuthCompat) GetLegacyGlobalConfig

func (c *AuthCompat) GetLegacyGlobalConfig(ctx context.Context) (*LegacyGlobalConfig, error)

func (*AuthCompat) Heartbeat

func (c *AuthCompat) Heartbeat() *HeartbeatResult

func (*AuthCompat) VerifySliderCaptcha

func (c *AuthCompat) VerifySliderCaptcha(ctx context.Context, id string, x, y int, trail string) (*SliderVerifyResult, error)

type CacheKeyPayload

type CacheKeyPayload struct {
	Code   string `json:"code"`
	LastAt int64  `json:"lastAt"`
}

CacheKeyPayload stores verification code in Redis

type CryptoSaaSConfig

type CryptoSaaSConfig struct {
	Endpoint  string `json:"endpoint"`
	AccountID string `json:"account_id"`
	SecretKey string `json:"secret_key"`
	Type      string `json:"type"`
}

CryptoSaaSConfig CryptoSaaS加密货币支付配置

func (*CryptoSaaSConfig) Unmarshal

func (c *CryptoSaaSConfig) Unmarshal(data []byte) error

type Data

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

Data

func NewData

func NewData(c *conf.Data, serverConf *conf.Server, appConf *conf.Application, logger log.Logger) (*Data, func(), error)

NewData

func (*Data) AppConf

func (d *Data) AppConf() *conf.Application

AppConf 获取应用配置

func (*Data) DB

func (d *Data) DB() *ent.Client

DB 获取数据库客户端

func (*Data) DeviceManager

func (d *Data) DeviceManager() *device.DeviceManager

DeviceManager 获取设备管理器

func (*Data) FindOne

func (d *Data) FindOne(ctx context.Context, userId int64) (*ent.ProxyUser, error)

FindOne 实现用户服务接口 - 根据用户ID查找用户

func (*Data) OnlineUserSubscribe

func (d *Data) OnlineUserSubscribe(ctx context.Context, serverID int64, protocol string) (OnlineUserSubscribe, error)

OnlineUserSubscribe 获取在线用户订阅信息 - 严格按照原始逻辑

func (*Data) Queue

func (d *Data) Queue() *asynq.Client

Queue 获取异步队列客户端

func (*Data) RDB

func (d *Data) RDB() *redis.Client

RDB 获取Redis客户端

func (*Data) Redis

func (d *Data) Redis() *redis.Client

Redis 获取Redis客户端 (为中间件兼容)

func (*Data) StatusCache

func (d *Data) StatusCache(ctx context.Context, serverID int) (*Status, error)

StatusCache 获取服务器状态缓存 - 严格按照原始逻辑

type DeviceLoginParams

type DeviceLoginParams struct {
	Identifier string
	ShortCode  string
	Meta       authbiz.RequestMeta
}

type EPayConfig

type EPayConfig struct {
	Pid  string `json:"pid"`
	Url  string `json:"url"`
	Key  string `json:"key"`
	Type string `json:"type"`
}

EPayConfig EPay支付配置

func (*EPayConfig) Unmarshal

func (c *EPayConfig) Unmarshal(data []byte) error

type GenerateCaptchaResult

type GenerateCaptchaResult struct {
	ID         string `json:"id"`
	Image      string `json:"image"`
	Type       string `json:"type"`
	BlockImage string `json:"block_image,omitempty"`
}

type HeartbeatResult

type HeartbeatResult struct {
	Status    bool   `json:"status"`
	Message   string `json:"message"`
	Timestamp int64  `json:"timestamp"`
}

type LegacyAuthConfig

type LegacyAuthConfig struct {
	Mobile   LegacyMobileAuthConfig     `json:"mobile"`
	Email    LegacyEmailAuthConfig      `json:"email"`
	Device   LegacyDeviceAuthConfig     `json:"device"`
	Register LegacyPublicRegisterConfig `json:"register"`
}

type LegacyCurrencyConfig

type LegacyCurrencyConfig struct {
	CurrencyUnit   string `json:"currency_unit"`
	CurrencySymbol string `json:"currency_symbol"`
}

type LegacyDeviceAuthConfig

type LegacyDeviceAuthConfig struct {
	Enable         bool `json:"enable"`
	ShowAds        bool `json:"show_ads"`
	EnableSecurity bool `json:"enable_security"`
	OnlyRealDevice bool `json:"only_real_device"`
}

type LegacyEmailAuthConfig

type LegacyEmailAuthConfig struct {
	Enable             bool   `json:"enable"`
	EnableVerify       bool   `json:"enable_verify"`
	EnableDomainSuffix bool   `json:"enable_domain_suffix"`
	DomainSuffixList   string `json:"domain_suffix_list"`
}

type LegacyGlobalConfig

type LegacyGlobalConfig struct {
	Site         LegacySiteConfig       `json:"site"`
	Verify       LegacyVerifyConfig     `json:"verify"`
	Auth         LegacyAuthConfig       `json:"auth"`
	Invite       LegacyInviteConfig     `json:"invite"`
	Currency     LegacyCurrencyConfig   `json:"currency"`
	Subscribe    LegacySubscribeConfig  `json:"subscribe"`
	VerifyCode   LegacyVerifyCodeConfig `json:"verify_code"`
	OAuthMethods []string               `json:"oauth_methods"`
	WebAd        bool                   `json:"web_ad"`
}

type LegacyInviteConfig

type LegacyInviteConfig struct {
	ForcedInvite       bool  `json:"forced_invite"`
	ReferralPercentage int64 `json:"referral_percentage"`
	OnlyFirstPurchase  bool  `json:"only_first_purchase"`
}

type LegacyMobileAuthConfig

type LegacyMobileAuthConfig struct {
	Enable          bool     `json:"enable"`
	EnableWhitelist bool     `json:"enable_whitelist"`
	Whitelist       []string `json:"whitelist"`
}

type LegacyPublicRegisterConfig

type LegacyPublicRegisterConfig struct {
	StopRegister            bool  `json:"stop_register"`
	EnableIpRegisterLimit   bool  `json:"enable_ip_register_limit"`
	IpRegisterLimit         int64 `json:"ip_register_limit"`
	IpRegisterLimitDuration int64 `json:"ip_register_limit_duration"`
}

type LegacySiteConfig

type LegacySiteConfig struct {
	Host       string `json:"host"`
	SiteName   string `json:"site_name"`
	SiteDesc   string `json:"site_desc"`
	Keywords   string `json:"keywords"`
	CustomHTML string `json:"custom_html"`
	CustomData string `json:"custom_data"`
}

type LegacySubscribeConfig

type LegacySubscribeConfig struct {
	SingleModel     bool   `json:"single_model"`
	SubscribePath   string `json:"subscribe_path"`
	SubscribeDomain string `json:"subscribe_domain"`
	PanDomain       bool   `json:"pan_domain"`
	UserAgentLimit  bool   `json:"user_agent_limit"`
	UserAgentList   string `json:"user_agent_list"`
}

type LegacyVerifyCodeConfig

type LegacyVerifyCodeConfig struct {
	VerifyCodeInterval int64 `json:"verify_code_interval"`
}

type LegacyVerifyConfig

type LegacyVerifyConfig struct {
	CaptchaType                    string `json:"captcha_type"`
	TurnstileSiteKey               string `json:"turnstile_site_key"`
	EnableUserLoginCaptcha         bool   `json:"enable_user_login_captcha"`
	EnableUserRegisterCaptcha      bool   `json:"enable_user_register_captcha"`
	EnableAdminLoginCaptcha        bool   `json:"enable_admin_login_captcha"`
	EnableUserResetPasswordCaptcha bool   `json:"enable_user_reset_password_captcha"`
}

type LoginLog

type LoginLog struct {
	Method    string `json:"method"`
	LoginIP   string `json:"login_ip"`
	UserAgent string `json:"user_agent"`
	Success   bool   `json:"success"`
	Timestamp int64  `json:"timestamp"`
}

type OnlineUserSubscribe

type OnlineUserSubscribe map[int64][]string

OnlineUserSubscribe 在线用户订阅映射 map[subscribeID][]IP

type PaymentConfigJSON

type PaymentConfigJSON struct {
	AppID         string `json:"app_id"`
	PrivateKey    string `json:"private_key"`
	PublicKey     string `json:"public_key"`
	WebhookSecret string `json:"webhook_secret"`
	InvoiceName   string `json:"invoice_name"`
	Sandbox       bool   `json:"sandbox"`
	EPayPid       string `json:"epay_pid"`
	EPayKey       string `json:"epay_key"`
	EPayURL       string `json:"epay_url"`
	NotifyURL     string `json:"notify_url"`
}

PaymentConfigJSON 支付配置JSON结构

type RegisterLog

type RegisterLog struct {
	AuthMethod string `json:"auth_method"`
	Identifier string `json:"identifier"`
	RegisterIP string `json:"register_ip"`
	UserAgent  string `json:"user_agent"`
	Timestamp  int64  `json:"timestamp"`
}

type ServerTrafficData

type ServerTrafficData struct {
	ServerID int64
	Name     string
	Upload   int64
	Download int64
}

ServerTrafficData 服务器流量数据

type SliderVerifyResult

type SliderVerifyResult struct {
	Token string `json:"token"`
}

type Status

type Status struct {
	CPU       float64 `json:"cpu"`
	Mem       float64 `json:"mem"`
	Disk      float64 `json:"disk"`
	UpdatedAt int     `json:"updated_at"`
}

Status 服务器状态

type StripeConfig

type StripeConfig struct {
	PublicKey     string `json:"public_key"`
	SecretKey     string `json:"secret_key"`
	WebhookSecret string `json:"webhook_secret"`
	Payment       string `json:"payment"` // card/alipay/wechat_pay
}

StripeConfig Stripe支付配置

func (*StripeConfig) Unmarshal

func (c *StripeConfig) Unmarshal(data []byte) error

type SubscribeDiscount

type SubscribeDiscount struct {
	Quantity int64 `json:"quantity"`
	Discount int64 `json:"discount"`
}

SubscribeDiscount 订阅折扣结构

type TrafficTotal

type TrafficTotal struct {
	Upload   int64
	Download int64
}

TrafficTotal 流量总计

type UserTrafficData

type UserTrafficData struct {
	UserID   int64
	Upload   int64
	Download int64
}

UserTrafficData 用户流量数据

Jump to

Keyboard shortcuts

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