Documentation
¶
Overview ¶
Package config 基础配置模块
Package config 数据库配置模块 ¶
Package config MCP配置模块 ¶
Package config 存储配置模块 ¶
Package config 上传下载配置模块 ¶
Package config 用户系统配置模块
Index ¶
- type BaseConfig
- type ConfigManager
- func (cm *ConfigManager) ApplySources(sources ...ConfigSource) error
- func (cm *ConfigManager) Clone() *ConfigManager
- func (cm *ConfigManager) GetAddress() string
- func (cm *ConfigManager) GetDB() *gorm.DB
- func (cm *ConfigManager) GetDatabaseDSN() (string, error)
- func (cm *ConfigManager) IsMCPEnabled() bool
- func (cm *ConfigManager) IsUserSystemEnabled() bool
- func (cm *ConfigManager) LoadFromYAML(path string) error
- func (cm *ConfigManager) PersistYAML() error
- func (cm *ConfigManager) ReloadConfig() error
- func (cm *ConfigManager) Save() error
- func (cm *ConfigManager) SetDB(db *gorm.DB)
- func (cm *ConfigManager) UpdateTransaction(apply func(draft *ConfigManager) error) error
- func (cm *ConfigManager) Validate() error
- type ConfigSource
- type ConfigSourceFunc
- type DatabaseConfig
- func (dc *DatabaseConfig) Clone() *DatabaseConfig
- func (dc *DatabaseConfig) GetDSN() (string, error)
- func (dc *DatabaseConfig) GetDefaultPort() int
- func (dc *DatabaseConfig) HasPassword() bool
- func (dc *DatabaseConfig) IsMySQL() bool
- func (dc *DatabaseConfig) IsPostgreSQL() bool
- func (dc *DatabaseConfig) IsSQLite() bool
- func (dc *DatabaseConfig) SetPassword(password string)
- func (dc *DatabaseConfig) Validate() error
- type DownloadConfig
- type EnvSource
- type MCPConfig
- type NFSConfig
- type OneDriveConfig
- type S3Config
- type StorageConfig
- type Theme
- type TransferConfig
- type UIConfig
- type UploadConfig
- func (uc *UploadConfig) Clone() *UploadConfig
- func (uc *UploadConfig) GetChunkSizeMB() float64
- func (uc *UploadConfig) GetMaxSaveHours() float64
- func (uc *UploadConfig) GetUploadSizeMB() float64
- func (uc *UploadConfig) IsChunkEnabled() bool
- func (uc *UploadConfig) IsLoginRequired() bool
- func (uc *UploadConfig) IsUploadEnabled() bool
- func (uc *UploadConfig) Validate() error
- type UserSystemConfig
- func (usc *UserSystemConfig) Clone() *UserSystemConfig
- func (usc *UserSystemConfig) DisableEmailVerify()
- func (usc *UserSystemConfig) DisableRegistration()
- func (usc *UserSystemConfig) EnableEmailVerify()
- func (usc *UserSystemConfig) EnableRegistration()
- func (usc *UserSystemConfig) GenerateRandomJWTSecret() error
- func (usc *UserSystemConfig) GetSessionDuration() time.Duration
- func (usc *UserSystemConfig) GetSessionExpiryDays() float64
- func (usc *UserSystemConfig) GetUserStorageQuotaGB() float64
- func (usc *UserSystemConfig) GetUserUploadSizeMB() float64
- func (usc *UserSystemConfig) IsEmailVerifyRequired() bool
- func (usc *UserSystemConfig) IsRegistrationAllowed() bool
- func (usc *UserSystemConfig) IsStorageQuotaUnlimited() bool
- func (usc *UserSystemConfig) IsUserSystemEnabled() bool
- func (usc *UserSystemConfig) SetSessionExpiryDays(days int) error
- func (usc *UserSystemConfig) SetUserStorageQuotaGB(quotaGB int64) error
- func (usc *UserSystemConfig) SetUserUploadSizeMB(sizeMB int64) error
- func (usc *UserSystemConfig) Validate() error
- type WebDAVConfig
- type YAMLFileSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseConfig ¶
type BaseConfig struct {
Name string `json:"name"`
Description string `json:"description"`
Keywords string `json:"keywords"`
Port int `json:"port"`
Host string `json:"host"`
DataPath string `json:"data_path"`
Production bool `json:"production"`
}
BaseConfig 基础配置
type ConfigManager ¶
type ConfigManager struct {
// === 核心配置模块 ===
Base *BaseConfig `json:"base" yaml:"base"`
Database *DatabaseConfig `json:"database" yaml:"database"`
Transfer *TransferConfig `json:"transfer" yaml:"transfer"`
Storage *StorageConfig `json:"storage" yaml:"storage"`
User *UserSystemConfig `json:"user" yaml:"user"`
MCP *MCPConfig `json:"mcp" yaml:"mcp"`
UI *UIConfig `json:"ui" yaml:"ui"`
// === 通知配置 ===
NotifyTitle string `json:"notify_title" yaml:"notify_title"`
NotifyContent string `json:"notify_content" yaml:"notify_content"`
// === 运行时元数据 ===
SysStart string `json:"sys_start" yaml:"sys_start"`
// === 业务配置(保持顶层以兼容性) ===
UploadMinute int `json:"upload_minute" yaml:"upload_minute"`
UploadCount int `json:"upload_count" yaml:"upload_count"`
ErrorMinute int `json:"error_minute" yaml:"error_minute"`
ErrorCount int `json:"error_count" yaml:"error_count"`
ExpireStyle []string `json:"expire_style" yaml:"expire_style"`
// contains filtered or unexported fields
}
ConfigManager 配置管理器,实现 环境变量 > YAML > 默认值 的优先级语义
func NewConfigManager ¶
func NewConfigManager() *ConfigManager
func (*ConfigManager) ApplySources ¶ added in v1.8.2
func (cm *ConfigManager) ApplySources(sources ...ConfigSource) error
ApplySources processes a group of configuration sources and collects errors.
func (*ConfigManager) GetAddress ¶
func (cm *ConfigManager) GetAddress() string
func (*ConfigManager) GetDB ¶ added in v1.7.1
func (cm *ConfigManager) GetDB() *gorm.DB
func (*ConfigManager) GetDatabaseDSN ¶
func (cm *ConfigManager) GetDatabaseDSN() (string, error)
func (*ConfigManager) IsMCPEnabled ¶
func (cm *ConfigManager) IsMCPEnabled() bool
func (*ConfigManager) IsUserSystemEnabled ¶
func (cm *ConfigManager) IsUserSystemEnabled() bool
func (*ConfigManager) LoadFromYAML ¶ added in v1.7.1
func (cm *ConfigManager) LoadFromYAML(path string) error
LoadFromYAML 从 YAML 文件加载配置
func (*ConfigManager) PersistYAML ¶ added in v1.7.1
func (cm *ConfigManager) PersistYAML() error
PersistYAML 将当前配置保存到 YAML 文件
func (*ConfigManager) ReloadConfig ¶
func (cm *ConfigManager) ReloadConfig() error
ReloadConfig 重新加载配置(仅支持环境变量,保持端口不变)
func (*ConfigManager) Save ¶
func (cm *ConfigManager) Save() error
Save 保存配置(已废弃,请使用 config.yaml 和环境变量)
func (*ConfigManager) SetDB ¶
func (cm *ConfigManager) SetDB(db *gorm.DB)
func (*ConfigManager) UpdateTransaction ¶ added in v1.9.5
func (cm *ConfigManager) UpdateTransaction(apply func(draft *ConfigManager) error) error
UpdateTransaction 在配置上执行事务式更新:先克隆、应用变更、落盘、重载;若任一步失败则回滚到原状态并恢复文件
type ConfigSource ¶ added in v1.8.2
type ConfigSource interface {
Apply(*ConfigManager) error
}
ConfigSource represents a configuration input that can mutate the manager state.
type ConfigSourceFunc ¶ added in v1.8.2
type ConfigSourceFunc func(*ConfigManager) error
ConfigSourceFunc allows plain functions to be used as ConfigSource.
func (ConfigSourceFunc) Apply ¶ added in v1.8.2
func (f ConfigSourceFunc) Apply(cm *ConfigManager) error
Apply executes the underlying function.
type DatabaseConfig ¶
type DatabaseConfig struct {
Type string `json:"database_type"` // sqlite, mysql, postgres
Host string `json:"database_host"`
Port int `json:"database_port"`
Name string `json:"database_name"`
User string `json:"database_user"`
Pass string `json:"database_pass"`
SSL string `json:"database_ssl"` // disable, require, verify-full (for postgres)
}
DatabaseConfig 数据库配置
func (*DatabaseConfig) GetDSN ¶
func (dc *DatabaseConfig) GetDSN() (string, error)
GetDSN 获取数据库连接字符串
func (*DatabaseConfig) GetDefaultPort ¶
func (dc *DatabaseConfig) GetDefaultPort() int
GetDefaultPort 获取默认端口
func (*DatabaseConfig) HasPassword ¶
func (dc *DatabaseConfig) HasPassword() bool
HasPassword 检查是否设置了密码
func (*DatabaseConfig) IsPostgreSQL ¶
func (dc *DatabaseConfig) IsPostgreSQL() bool
IsPostgreSQL 判断是否为PostgreSQL数据库
func (*DatabaseConfig) SetPassword ¶
func (dc *DatabaseConfig) SetPassword(password string)
SetPassword 安全地设置密码
type DownloadConfig ¶
type DownloadConfig struct {
EnableConcurrentDownload int `json:"enable_concurrent_download"` // 是否启用并发下载
MaxConcurrentDownloads int `json:"max_concurrent_downloads"` // 最大并发下载数
DownloadTimeout int `json:"download_timeout"` // 下载超时时间(秒)
RequireLogin int `json:"require_login"` // 下载是否强制登录 0-否 1-是
}
DownloadConfig 下载配置
func (*DownloadConfig) GetDownloadTimeoutMinutes ¶
func (dc *DownloadConfig) GetDownloadTimeoutMinutes() float64
GetDownloadTimeoutMinutes 获取下载超时时间(分钟)
func (*DownloadConfig) IsDownloadConcurrentEnabled ¶
func (dc *DownloadConfig) IsDownloadConcurrentEnabled() bool
IsDownloadConcurrentEnabled 判断是否启用并发下载
func (*DownloadConfig) IsLoginRequired ¶ added in v1.9.5
func (dc *DownloadConfig) IsLoginRequired() bool
IsLoginRequired 判断是否需要登录才能下载
type EnvSource ¶ added in v1.8.2
type EnvSource struct {
// contains filtered or unexported fields
}
EnvSource mutates configuration using environment variables.
func NewDefaultEnvSource ¶ added in v1.8.2
func NewDefaultEnvSource() EnvSource
NewDefaultEnvSource returns the built-in environment overrides.
func (EnvSource) Apply ¶ added in v1.8.2
func (s EnvSource) Apply(cm *ConfigManager) error
Apply applies every configured override.
type MCPConfig ¶
type MCPConfig struct {
EnableMCPServer int `json:"enable_mcp_server"` // 是否启用 MCP 服务器
MCPPort string `json:"mcp_port"` // MCP 服务器端口
MCPHost string `json:"mcp_host"` // MCP 服务器绑定地址
}
MCPConfig MCP服务器配置
type NFSConfig ¶
type NFSConfig struct {
Server string `json:"nfs_server"` // NFS服务器地址
Path string `json:"nfs_path"` // NFS路径
MountPoint string `json:"nfs_mount_point"` // 本地挂载点
Version string `json:"nfs_version"` // NFS版本
Options string `json:"nfs_options"` // 挂载选项
Timeout int `json:"nfs_timeout"` // 超时时间(秒)
AutoMount int `json:"nfs_auto_mount"` // 是否自动挂载
RetryCount int `json:"nfs_retry_count"` // 重试次数
SubPath string `json:"nfs_sub_path"` // 子路径
}
NFSConfig NFS存储配置
type OneDriveConfig ¶
type OneDriveConfig struct {
Domain string `json:"onedrive_domain"`
ClientID string `json:"onedrive_client_id"`
Username string `json:"onedrive_username"`
Password string `json:"onedrive_password"`
RootPath string `json:"onedrive_root_path"`
Proxy int `json:"onedrive_proxy"`
}
OneDriveConfig OneDrive存储配置
type S3Config ¶
type S3Config struct {
AccessKeyID string `json:"s3_access_key_id"`
SecretAccessKey string `json:"s3_secret_access_key"`
BucketName string `json:"s3_bucket_name"`
EndpointURL string `json:"s3_endpoint_url"`
RegionName string `json:"s3_region_name"`
SignatureVersion string `json:"s3_signature_version"`
Hostname string `json:"s3_hostname"`
Proxy int `json:"s3_proxy"`
SessionToken string `json:"aws_session_token"`
}
S3Config S3存储配置
type StorageConfig ¶
type StorageConfig struct {
Type string `json:"file_storage"` // local, s3, webdav, onedrive, nfs
StoragePath string `json:"storage_path"`
S3 *S3Config `json:"s3,omitempty"`
WebDAV *WebDAVConfig `json:"webdav,omitempty"`
OneDrive *OneDriveConfig `json:"onedrive,omitempty"`
NFS *NFSConfig `json:"nfs,omitempty"`
}
StorageConfig 存储配置
func (*StorageConfig) IsOneDrive ¶
func (sc *StorageConfig) IsOneDrive() bool
IsOneDrive 判断是否为OneDrive存储
type Theme ¶
type Theme struct {
Name string `json:"name"`
Key string `json:"key"`
Author string `json:"author"`
Version string `json:"version"`
}
Theme 主题配置
type TransferConfig ¶
type TransferConfig struct {
Upload *UploadConfig `json:"upload"`
Download *DownloadConfig `json:"download"`
}
TransferConfig 文件传输配置(包含上传和下载)
type UIConfig ¶ added in v1.7.1
type UIConfig struct {
ThemesSelect string `yaml:"themes_select" json:"themes_select"`
Background string `yaml:"background" json:"background"`
PageExplain string `yaml:"page_explain" json:"page_explain"`
RobotsText string `yaml:"robots_text" json:"robots_text"`
ShowAdminAddr int `yaml:"show_admin_addr" json:"show_admin_addr"`
Opacity float64 `yaml:"opacity" json:"opacity"`
}
UIConfig holds theme and page related configuration and is stored under `ui` in config.yaml.
type UploadConfig ¶
type UploadConfig struct {
OpenUpload int `json:"open_upload"` // 是否开启上传 0-禁用 1-启用
UploadSize int64 `json:"upload_size"` // 上传文件大小限制(字节)
EnableChunk int `json:"enable_chunk"` // 是否启用分片上传 0-禁用 1-启用
ChunkSize int64 `json:"chunk_size"` // 分片大小(字节)
MaxSaveSeconds int `json:"max_save_seconds"` // 最大保存时间(秒)
RequireLogin int `json:"require_login"` // 上传是否强制登录 0-否 1-是
}
UploadConfig 上传配置
func (*UploadConfig) GetChunkSizeMB ¶
func (uc *UploadConfig) GetChunkSizeMB() float64
GetChunkSizeMB 获取分片大小(MB)
func (*UploadConfig) GetMaxSaveHours ¶
func (uc *UploadConfig) GetMaxSaveHours() float64
GetMaxSaveHours 获取最大保存时间(小时)
func (*UploadConfig) GetUploadSizeMB ¶
func (uc *UploadConfig) GetUploadSizeMB() float64
GetUploadSizeMB 获取上传大小限制(MB)
func (*UploadConfig) IsChunkEnabled ¶
func (uc *UploadConfig) IsChunkEnabled() bool
IsChunkEnabled 判断是否启用分片上传
func (*UploadConfig) IsLoginRequired ¶ added in v1.9.5
func (uc *UploadConfig) IsLoginRequired() bool
IsLoginRequired 判断是否需要登录才能上传
func (*UploadConfig) IsUploadEnabled ¶
func (uc *UploadConfig) IsUploadEnabled() bool
IsUploadEnabled 判断是否启用上传
type UserSystemConfig ¶
type UserSystemConfig struct {
AllowUserRegistration int `yaml:"allowuserregistration" json:"allow_user_registration"` // 是否允许用户注册
RequireEmailVerify int `yaml:"requireemailverify" json:"require_email_verify"` // 是否需要邮箱验证
UserUploadSize int64 `yaml:"useruploadsize" json:"user_upload_size"` // 用户上传文件大小限制
UserStorageQuota int64 `yaml:"userstoragequota" json:"user_storage_quota"` // 用户存储配额
SessionExpiryHours int `yaml:"sessionexpiryhours" json:"session_expiry_hours"` // 用户会话过期时间
MaxSessionsPerUser int `yaml:"maxsessionsperuser" json:"max_sessions_per_user"` // 每个用户最大会话数
JWTSecret string `yaml:"jwtsecret" json:"jwt_secret"` // JWT签名密钥
}
UserSystemConfig 用户系统配置
func NewUserSystemConfig ¶
func NewUserSystemConfig() *UserSystemConfig
NewUserSystemConfig 创建用户系统配置
func (*UserSystemConfig) DisableEmailVerify ¶
func (usc *UserSystemConfig) DisableEmailVerify()
DisableEmailVerify 禁用邮箱验证
func (*UserSystemConfig) DisableRegistration ¶
func (usc *UserSystemConfig) DisableRegistration()
DisableRegistration 禁用用户注册
func (*UserSystemConfig) EnableEmailVerify ¶
func (usc *UserSystemConfig) EnableEmailVerify()
EnableEmailVerify 启用邮箱验证
func (*UserSystemConfig) EnableRegistration ¶
func (usc *UserSystemConfig) EnableRegistration()
EnableRegistration 启用用户注册
func (*UserSystemConfig) GenerateRandomJWTSecret ¶
func (usc *UserSystemConfig) GenerateRandomJWTSecret() error
GenerateRandomJWTSecret 生成随机JWT密钥
func (*UserSystemConfig) GetSessionDuration ¶
func (usc *UserSystemConfig) GetSessionDuration() time.Duration
GetSessionDuration 获取会话持续时间
func (*UserSystemConfig) GetSessionExpiryDays ¶
func (usc *UserSystemConfig) GetSessionExpiryDays() float64
GetSessionExpiryDays 获取会话过期天数
func (*UserSystemConfig) GetUserStorageQuotaGB ¶
func (usc *UserSystemConfig) GetUserStorageQuotaGB() float64
GetUserStorageQuotaGB 获取用户存储配额(GB)
func (*UserSystemConfig) GetUserUploadSizeMB ¶
func (usc *UserSystemConfig) GetUserUploadSizeMB() float64
GetUserUploadSizeMB 获取用户上传大小限制(MB)
func (*UserSystemConfig) IsEmailVerifyRequired ¶
func (usc *UserSystemConfig) IsEmailVerifyRequired() bool
IsEmailVerifyRequired 判断是否需要邮箱验证
func (*UserSystemConfig) IsRegistrationAllowed ¶
func (usc *UserSystemConfig) IsRegistrationAllowed() bool
IsRegistrationAllowed 判断是否允许用户注册
func (*UserSystemConfig) IsStorageQuotaUnlimited ¶
func (usc *UserSystemConfig) IsStorageQuotaUnlimited() bool
IsStorageQuotaUnlimited 判断存储配额是否无限制
func (*UserSystemConfig) IsUserSystemEnabled ¶
func (usc *UserSystemConfig) IsUserSystemEnabled() bool
IsUserSystemEnabled 判断是否启用用户系统 - 始终返回true
func (*UserSystemConfig) SetSessionExpiryDays ¶
func (usc *UserSystemConfig) SetSessionExpiryDays(days int) error
SetSessionExpiryDays 设置会话过期天数
func (*UserSystemConfig) SetUserStorageQuotaGB ¶
func (usc *UserSystemConfig) SetUserStorageQuotaGB(quotaGB int64) error
SetUserStorageQuotaGB 设置用户存储配额(GB)
func (*UserSystemConfig) SetUserUploadSizeMB ¶
func (usc *UserSystemConfig) SetUserUploadSizeMB(sizeMB int64) error
SetUserUploadSizeMB 设置用户上传大小限制(MB)
type WebDAVConfig ¶
type WebDAVConfig struct {
Hostname string `json:"webdav_hostname"`
RootPath string `json:"webdav_root_path"`
Proxy int `json:"webdav_proxy"`
URL string `json:"webdav_url"`
Password string `json:"webdav_password"`
Username string `json:"webdav_username"`
}
WebDAVConfig WebDAV存储配置
type YAMLFileSource ¶ added in v1.8.2
type YAMLFileSource struct {
Path string
}
YAMLFileSource loads configuration values from a YAML file.
func (YAMLFileSource) Apply ¶ added in v1.8.2
func (s YAMLFileSource) Apply(cm *ConfigManager) error
Apply reads and merges YAML content into the manager.