Files
hldrCenter/server/config/config.go

70 lines
1.8 KiB
Go
Raw Normal View History

2025-10-04 20:48:50 +08:00
package config
import (
"os"
"gopkg.in/yaml.v3"
)
// Config 应用配置结构体
type Config struct {
2025-10-31 17:35:44 +08:00
Server ServerConfig `yaml:"server"`
OSS OSSConfig `yaml:"oss"`
MySQL MySQLConfig `yaml:"mysql"`
Upload UploadConfig `yaml:"upload"`
FileUpload FileUploadConfig `yaml:"fileupload"`
2025-10-04 20:48:50 +08:00
}
// ServerConfig 服务器配置
type ServerConfig struct {
Port string `yaml:"port"`
AllowedOrigins []string `yaml:"allowed_origins"`
}
// OSSConfig 阿里云OSS配置
type OSSConfig struct {
Endpoint string `yaml:"endpoint"`
BucketName string `yaml:"bucket_name"`
AccessKeyID string `yaml:"access_key_id"`
AccessKeySecret string `yaml:"access_key_secret"`
ObjectPrefix string `yaml:"object_prefix"`
}
// MySQLConfig MySQL数据库配置
type MySQLConfig struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
Username string `yaml:"username"`
Password string `yaml:"password"`
Database string `yaml:"database"`
Charset string `yaml:"charset"`
}
// UploadConfig 上传配置
type UploadConfig struct {
AllowImageTypes string `yaml:"allow_image_types"`
MaxFileSize int64 `yaml:"max_file_size"`
}
2025-10-31 17:35:44 +08:00
type FileUploadConfig struct {
MaxFileSize int64 `yaml:"max_file_size"` // 最大文件大小(字节)
AllowFileTypes string `yaml:"allow_file_types"` // 允许的文件类型,用逗号分隔
ChunkSize int64 `yaml:"chunk_size"` // 分片大小5MB
TempDir string `yaml:"temp_dir"` // 分片临时存储目录
}
2025-10-04 20:48:50 +08:00
// LoadConfig 从文件加载配置
func LoadConfig(filename string) (*Config, error) {
data, err := os.ReadFile(filename)
if err != nil {
return nil, err
}
var config Config
if err := yaml.Unmarshal(data, &config); err != nil {
return nil, err
}
return &config, nil
}