项目初始化

This commit is contained in:
2026-01-13 17:00:49 +08:00
commit d2352318f4
27 changed files with 4343 additions and 0 deletions

82
internal/config/config.go Normal file
View File

@@ -0,0 +1,82 @@
package config
import (
"os"
"gopkg.in/yaml.v3"
)
type Config struct {
Site SiteConfig `yaml:"site"`
Security SecurityConfig `yaml:"security"`
Upload UploadConfig `yaml:"upload"`
Storage StorageConfig `yaml:"storage"`
APIToken APITokenConfig `yaml:"api_token"`
Database DatabaseConfig `yaml:"database"`
}
type SiteConfig struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
}
type SecurityConfig struct {
AdminPasswordHash string `yaml:"admin_password_hash"`
PickupCodeLength int `yaml:"pickup_code_length"`
PickupFailLimit int `yaml:"pickup_fail_limit"`
JWTSecret string `yaml:"jwt_secret"`
}
type UploadConfig struct {
MaxFileSizeMB int64 `yaml:"max_file_size_mb"`
MaxBatchFiles int `yaml:"max_batch_files"`
MaxRetentionDays int `yaml:"max_retention_days"`
}
type StorageConfig struct {
Type string `yaml:"type"`
Local struct {
Path string `yaml:"path"`
} `yaml:"local"`
WebDAV struct {
URL string `yaml:"url"`
Username string `yaml:"username"`
Password string `yaml:"password"`
Root string `yaml:"root"`
} `yaml:"webdav"`
S3 struct {
Endpoint string `yaml:"endpoint"`
Region string `yaml:"region"`
AccessKey string `yaml:"access_key"`
SecretKey string `yaml:"secret_key"`
Bucket string `yaml:"bucket"`
UseSSL bool `yaml:"use_ssl"`
} `yaml:"s3"`
}
type APITokenConfig struct {
Enabled bool `yaml:"enabled"`
AllowAdminAPI bool `yaml:"allow_admin_api"`
MaxTokens int `yaml:"max_tokens"`
}
type DatabaseConfig struct {
Path string `yaml:"path"`
}
var GlobalConfig *Config
func LoadConfig(path string) error {
data, err := os.ReadFile(path)
if err != nil {
return err
}
var cfg Config
if err := yaml.Unmarshal(data, &cfg); err != nil {
return err
}
GlobalConfig = &cfg
return nil
}