添加本地上传的功能

This commit is contained in:
2026-01-30 21:40:21 +08:00
parent 38ebe73e45
commit a6e8101e09
16 changed files with 531 additions and 58 deletions

View File

@@ -2,12 +2,13 @@
## 概述
配置工具提供了从外部文件加载和管理应用配置的功能支持数据库、OSS、Redis、CORS、MinIO、邮件、短信等常用服务的配置。
配置工具提供了从外部文件加载和管理应用配置的功能,支持数据库、LocalStorage、OSS、Redis、CORS、MinIO、邮件、短信等常用服务的配置。
## 功能特性
- 支持从外部JSON文件加载配置
- 支持数据库配置MySQL、PostgreSQL、SQLite
- 支持本地存储配置LocalStorage文件上传保存到本地文件夹
- 支持OSS对象存储配置阿里云、腾讯云、AWS、七牛云等
- 支持Redis配置
- 支持CORS配置与middleware包集成
@@ -75,6 +76,10 @@
"region": "us-east-1",
"domain": "http://localhost:9000"
},
"localStorage": {
"baseDir": "./uploads",
"publicURL": "http://localhost:8080/file?key={objectKey}"
},
"email": {
"host": "smtp.example.com",
"port": 587,
@@ -196,6 +201,16 @@ if minioConfig != nil {
}
```
### 6.1 获取本地存储配置LocalStorage
```go
localCfg := config.GetLocalStorage()
if localCfg != nil {
fmt.Printf("Local baseDir: %s\n", localCfg.BaseDir)
fmt.Printf("Local publicURL: %s\n", localCfg.PublicURL)
}
```
## 配置项说明
### DatabaseConfig 数据库配置
@@ -266,6 +281,13 @@ if minioConfig != nil {
| Region | string | 区域 |
| Domain | string | 自定义域名 |
### LocalStorageConfig 本地存储配置
| 字段 | 类型 | 说明 |
|------|------|------|
| BaseDir | string | 本地文件保存根目录(必填) |
| PublicURL | string | 对外访问 URL可选。包含 `{objectKey}` 占位符时会替换为 `url.QueryEscape(objectKey)`;不包含时作为 URL 前缀拼接 |
### EmailConfig 邮件配置
| 字段 | 类型 | 说明 | 默认值 |