Documentation
¶
Index ¶
- func GenerateRandomKey() string
- func GetKeyPrefix(key string) string
- func HashAPIKey(key string) string
- type APIKeyData
- type CreateAPIKeyReq
- type CreateAPIKeyResp
- type CreateUserReq
- type DefaultsProvider
- type QuotaExceededError
- type Service
- func (s *Service) ChangePassword(ctx context.Context, userID uint, oldPassword, newPassword string) error
- func (s *Service) CheckQuota(ctx context.Context, userID uint, addBytes int64) error
- func (s *Service) Create(ctx context.Context, req *CreateUserReq) (*model.UserResp, error)
- func (s *Service) CreateAPIKey(ctx context.Context, userID uint, req *CreateAPIKeyReq) (*CreateAPIKeyResp, error)
- func (s *Service) Delete(ctx context.Context, id uint) error
- func (s *Service) DeleteAPIKey(ctx context.Context, userID, id uint) error
- func (s *Service) GetByID(ctx context.Context, id uint) (*model.UserResp, error)
- func (s *Service) GetStats(ctx context.Context, userID uint) (*model.UserStats, error)
- func (s *Service) GetUploadSizeCap(ctx context.Context, userID uint) int64
- func (s *Service) GetUserFiles(ctx context.Context, userID uint, page, pageSize int) (*usermodel.UserFileList, error)
- func (s *Service) List(ctx context.Context, page, pageSize int) ([]*model.UserResp, int64, error)
- func (s *Service) ListAPIKeys(ctx context.Context, userID uint) ([]*APIKeyData, error)
- func (s *Service) Login(ctx context.Context, username, password string) (*model.UserResp, string, error)
- func (s *Service) LoginByEmail(ctx context.Context, email, password string) (*model.UserResp, string, error)
- func (s *Service) RegistrationAllowed(ctx context.Context) bool
- func (s *Service) RevokeAllAPIKeys(ctx context.Context, userID uint) (int64, error)
- func (s *Service) SetDefaultsProvider(p DefaultsProvider)
- func (s *Service) SetStorageQuota(ctx context.Context, userID uint, quota int64) (*model.UserResp, error)
- func (s *Service) SetUploadSize(ctx context.Context, userID uint, size int64) (*model.UserResp, error)
- func (s *Service) SystemDefaultStorageQuota(ctx context.Context) int64
- func (s *Service) Update(ctx context.Context, id uint, req *UpdateUserReq) (*model.UserResp, error)
- func (s *Service) UpdateUserStats(userID uint, statsType string, value int64) error
- type UpdateUserReq
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateRandomKey ¶
func GenerateRandomKey() string
GenerateRandomKey 生成32位随机字符串(16字节 hex,crypto/rand 经 kit/uidgen 统一收口; crypto/rand 不可用属进程级灾难,uidgen 以 panic 上抛而非返回 error)
Types ¶
type APIKeyData ¶
type APIKeyData struct {
ID uint
Name string
Prefix string
LastUsedAt *time.Time
LastUsedIP string
ExpiresAt *time.Time
CreatedAt *time.Time
Revoked bool
// RevokedAt 撤销时间(软撤销:DB 一直有值,但此前**响应里没有这个字段**
// ⇒ 用户/前端看不到「这把 Key 是什么时候被撤销的」⇒ 审计信息断在回传面。
// 2026-10-30 真机实录补齐;nil = 未撤销。
RevokedAt *time.Time
// Scopes 权限范围(空 = 全量)。
Scopes []string
}
APIKeyData API Key 数据
type CreateAPIKeyReq ¶
type CreateAPIKeyReq struct {
Name string
ExpiresAt *time.Time
ExpiresInDays *int64
// Scopes 权限范围(2026-10-30):该 Key 被允许的能力面;**空 = 全量**
// (与 scopes 机制引入前完全一致 ⇒ 老 Key 无需重建)。
Scopes []string
}
CreateAPIKeyReq 创建 API Key 请求
type CreateAPIKeyResp ¶
type CreateAPIKeyResp struct {
Key string
APIKey *APIKeyData
}
CreateAPIKeyResp 创建 API Key 响应
type CreateUserReq ¶
type DefaultsProvider ¶
type DefaultsProvider interface {
// DefaultStorageQuota 用户存储配额默认值(字节,0 = 不限)
DefaultStorageQuota(ctx context.Context) int64
// DefaultUploadSize 单次上传大小默认上限(字节,0 = 不限)
DefaultUploadSize(ctx context.Context) int64
// AllowUserRegistration 是否开放注册(管理后台"用户配置"持久化值优先)
AllowUserRegistration(ctx context.Context) bool
}
DefaultsProvider 系统级用户默认值来源(管理后台持久化配置优先,回退 yaml)。 消费侧接口:bootstrap 注入 admin 域适配器;未注入时回退全局 conf—— 本域不依赖 admin 包(跨域依赖收口为装配点)。
type QuotaExceededError ¶
type QuotaExceededError struct{ Msg string }
QuotaExceededError 存储配额超限(handler 侧可断言后返回 CodeStorageQuota)
func (*QuotaExceededError) ErrCode ¶
func (e *QuotaExceededError) ErrCode() int
func (*QuotaExceededError) Error ¶
func (e *QuotaExceededError) Error() string
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func (*Service) ChangePassword ¶
func (s *Service) ChangePassword(ctx context.Context, userID uint, oldPassword, newPassword string) error
ChangePassword 修改密码
func (*Service) CheckQuota ¶
CheckQuota 存储配额强制检查(上传前调用)。 生效优先级:用户级 MaxStorageQuota > 系统默认 user.user_storage_quota;0 = 不限。 已用配额以 file_codes 表实时聚合为准(比 users.total_storage 计数器更抗漂移)。
func (*Service) CreateAPIKey ¶
func (s *Service) CreateAPIKey(ctx context.Context, userID uint, req *CreateAPIKeyReq) (*CreateAPIKeyResp, error)
CreateAPIKey 为用户创建新的 API Key
func (*Service) DeleteAPIKey ¶
DeleteAPIKey 撤销指定的 API Key
func (*Service) GetUploadSizeCap ¶
GetUploadSizeCap 生效的单次上传大小上限(接线:此前 users.max_upload_size 字段存在但上传链路从不读取,管理员给用户降限无实际效果)。 优先级:用户级 MaxUploadSize > 系统默认 user.user_upload_size;0 = 不限。 用户不存在/查询失败返回 0(不阻断,配额类是运营约束)。
func (*Service) GetUserFiles ¶
func (s *Service) GetUserFiles(ctx context.Context, userID uint, page, pageSize int) (*usermodel.UserFileList, error)
GetUserFiles 获取用户文件列表(支持分页)
func (*Service) ListAPIKeys ¶
ListAPIKeys 获取用户的全部 API Key 列表(包含已撤销)
func (*Service) Login ¶
func (s *Service) Login(ctx context.Context, username, password string) (*model.UserResp, string, error)
Login 用户登录
func (*Service) LoginByEmail ¶
func (s *Service) LoginByEmail(ctx context.Context, email, password string) (*model.UserResp, string, error)
LoginByEmail 通过邮箱登录
func (*Service) RegistrationAllowed ¶ added in v0.15.1
RegistrationAllowed 是否开放注册(系统级设置来源:注入 provider 的管理后台 持久化值优先,未注入回退 yaml)。gen/handler/user 的 Register 入口经此消费, 不再直接 import admin 域包级单例(跨面依赖收口为装配点,2026-10-10)。
func (*Service) RevokeAllAPIKeys ¶
RevokeAllAPIKeys 一键吊销用户全部有效 API Key(应急止损),返回吊销数量。
func (*Service) SetDefaultsProvider ¶
func (s *Service) SetDefaultsProvider(p DefaultsProvider)
SetDefaultsProvider 注入系统级默认值来源(bootstrap 装配调用)。
func (*Service) SetStorageQuota ¶
func (s *Service) SetStorageQuota(ctx context.Context, userID uint, quota int64) (*model.UserResp, error)
SetStorageQuota 管理员设置用户存储配额(0 = 不限,回退系统默认)
func (*Service) SetUploadSize ¶
func (s *Service) SetUploadSize(ctx context.Context, userID uint, size int64) (*model.UserResp, error)
SetUploadSize 管理员设置用户单次上传大小上限(0 = 用系统默认)
func (*Service) SystemDefaultStorageQuota ¶ added in v0.15.1
SystemDefaultStorageQuota 系统级默认存储配额(字节,0 = 不限)。 与域内配额闸(defaultStorageQuota)同源;供 handler 展示层消费 (用户级 max_storage_quota 覆盖仍由调用方自行优先)。