config

package
v1.11.2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config 基础配置模块

Package config 数据库配置模块

Package config MCP配置模块

Package config 存储配置模块

Package config 上传下载配置模块

Package config 用户系统配置模块

Index

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 基础配置

func NewBaseConfig

func NewBaseConfig() *BaseConfig

NewBaseConfig 创建基础配置

func (*BaseConfig) Clone

func (bc *BaseConfig) Clone() *BaseConfig

Clone 克隆配置

func (*BaseConfig) GetAddress

func (bc *BaseConfig) GetAddress() string

GetAddress 获取完整的监听地址

func (*BaseConfig) IsLocalhost

func (bc *BaseConfig) IsLocalhost() bool

IsLocalhost 判断是否为本地地址

func (*BaseConfig) IsPublic

func (bc *BaseConfig) IsPublic() bool

IsPublic 判断是否为公网地址

func (*BaseConfig) Validate

func (bc *BaseConfig) Validate() error

Validate 验证基础配置

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 InitManager

func InitManager() *ConfigManager

InitManager 初始化配置管理器,加载 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) Clone

func (cm *ConfigManager) Clone() *ConfigManager

Clone 创建配置管理器的深拷贝

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 在配置上执行事务式更新:先克隆、应用变更、落盘、重载;若任一步失败则回滚到原状态并恢复文件

func (*ConfigManager) Validate

func (cm *ConfigManager) Validate() error

Validate 验证所有配置模块

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 NewDatabaseConfig

func NewDatabaseConfig() *DatabaseConfig

NewDatabaseConfig 创建数据库配置

func (*DatabaseConfig) Clone

func (dc *DatabaseConfig) Clone() *DatabaseConfig

Clone 克隆配置

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) IsMySQL

func (dc *DatabaseConfig) IsMySQL() bool

IsMySQL 判断是否为MySQL数据库

func (*DatabaseConfig) IsPostgreSQL

func (dc *DatabaseConfig) IsPostgreSQL() bool

IsPostgreSQL 判断是否为PostgreSQL数据库

func (*DatabaseConfig) IsSQLite

func (dc *DatabaseConfig) IsSQLite() bool

IsSQLite 判断是否为SQLite数据库

func (*DatabaseConfig) SetPassword

func (dc *DatabaseConfig) SetPassword(password string)

SetPassword 安全地设置密码

func (*DatabaseConfig) Validate

func (dc *DatabaseConfig) Validate() error

Validate 验证数据库配置

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 NewDownloadConfig

func NewDownloadConfig() *DownloadConfig

NewDownloadConfig 创建下载配置

func (*DownloadConfig) Clone

func (dc *DownloadConfig) Clone() *DownloadConfig

Clone 克隆下载配置

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 判断是否需要登录才能下载

func (*DownloadConfig) Validate

func (dc *DownloadConfig) Validate() error

Validate 验证下载配置

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服务器配置

func NewMCPConfig

func NewMCPConfig() *MCPConfig

NewMCPConfig 创建MCP配置

func (*MCPConfig) Clone

func (mc *MCPConfig) Clone() *MCPConfig

Update 更新配置 Clone 克隆配置

func (*MCPConfig) IsMCPEnabled

func (mc *MCPConfig) IsMCPEnabled() bool

IsMCPEnabled 判断是否启用MCP服务器

func (*MCPConfig) Validate

func (mc *MCPConfig) Validate() error

Validate 验证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存储配置

func NewNFSConfig

func NewNFSConfig() *NFSConfig

NewNFSConfig 创建NFS配置

func (*NFSConfig) Clone

func (nc *NFSConfig) Clone() *NFSConfig

Clone 克隆NFS配置

func (*NFSConfig) Validate

func (nc *NFSConfig) Validate() error

Validate 验证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存储配置

func NewOneDriveConfig

func NewOneDriveConfig() *OneDriveConfig

NewOneDriveConfig 创建OneDrive配置

func (*OneDriveConfig) Clone

func (oc *OneDriveConfig) Clone() *OneDriveConfig

Clone 克隆OneDrive配置

func (*OneDriveConfig) Validate

func (oc *OneDriveConfig) Validate() error

Validate 验证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存储配置

func NewS3Config

func NewS3Config() *S3Config

NewS3Config 创建S3配置

func (*S3Config) Clone

func (s3c *S3Config) Clone() *S3Config

Clone 克隆S3配置

func (*S3Config) Validate

func (s3c *S3Config) Validate() error

Validate 验证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 NewStorageConfig

func NewStorageConfig() *StorageConfig

NewStorageConfig 创建存储配置

func (*StorageConfig) Clone

func (sc *StorageConfig) Clone() *StorageConfig

Clone 克隆存储配置

func (*StorageConfig) IsLocal

func (sc *StorageConfig) IsLocal() bool

IsLocal 判断是否为本地存储

func (*StorageConfig) IsNFS

func (sc *StorageConfig) IsNFS() bool

IsNFS 判断是否为NFS存储

func (*StorageConfig) IsOneDrive

func (sc *StorageConfig) IsOneDrive() bool

IsOneDrive 判断是否为OneDrive存储

func (*StorageConfig) IsS3

func (sc *StorageConfig) IsS3() bool

IsS3 判断是否为S3存储

func (*StorageConfig) IsWebDAV

func (sc *StorageConfig) IsWebDAV() bool

IsWebDAV 判断是否为WebDAV存储

func (*StorageConfig) Validate

func (sc *StorageConfig) Validate() error

Validate 验证存储配置

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 文件传输配置(包含上传和下载)

func NewTransferConfig

func NewTransferConfig() *TransferConfig

NewTransferConfig 创建传输配置

func (*TransferConfig) Clone

func (tc *TransferConfig) Clone() *TransferConfig

Clone 克隆传输配置

func (*TransferConfig) Validate

func (tc *TransferConfig) Validate() error

Validate 验证传输配置

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 NewUploadConfig

func NewUploadConfig() *UploadConfig

NewUploadConfig 创建上传配置

func (*UploadConfig) Clone

func (uc *UploadConfig) Clone() *UploadConfig

Clone 克隆上传配置

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 判断是否启用上传

func (*UploadConfig) Validate

func (uc *UploadConfig) Validate() error

Validate 验证上传配置

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) Clone

func (usc *UserSystemConfig) Clone() *UserSystemConfig

Clone 克隆配置

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)

func (*UserSystemConfig) Validate

func (usc *UserSystemConfig) Validate() error

Validate 验证用户系统配置

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存储配置

func NewWebDAVConfig

func NewWebDAVConfig() *WebDAVConfig

NewWebDAVConfig 创建WebDAV配置

func (*WebDAVConfig) Clone

func (wc *WebDAVConfig) Clone() *WebDAVConfig

Clone 克隆WebDAV配置

func (*WebDAVConfig) Validate

func (wc *WebDAVConfig) Validate() error

Validate 验证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.

Jump to

Keyboard shortcuts

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