20260719215738
This commit is contained in:
1 parent
35aa108a34
commit
cda7f16d3a
116 files changed
+11826
-3669
No files matched your search
@@ -14,10 +14,8 @@ func Load() (*Config, error) {
|
||||
v := viper.New()
|
||||
v.SetConfigType("yaml")
|
||||
|
||||
// ✅ 默认值
|
||||
setDefaults(v)
|
||||
|
||||
// ✅ 支持环境变量(如 APP_PORT → app.port)
|
||||
v.AutomaticEnv()
|
||||
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||
|
||||
@@ -34,7 +32,6 @@ func Load() (*Config, error) {
|
||||
v.SetConfigName(envConfigName)
|
||||
|
||||
if err := v.MergeInConfig(); err != nil {
|
||||
// dev 可以没有,prod 必须有
|
||||
if env == "prod" {
|
||||
return nil, fmt.Errorf("读取环境配置失败(%s): %w", env, err)
|
||||
}
|
||||
@@ -48,13 +45,10 @@ func Load() (*Config, error) {
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
// ✅ 默认值统一在这里管理
|
||||
func setDefaults(v *viper.Viper) {
|
||||
v.SetDefault("app.name", "allapp-go")
|
||||
v.SetDefault("app.name", "app")
|
||||
v.SetDefault("app.port", 8080)
|
||||
v.SetDefault("app.base_url", "app")
|
||||
|
||||
// 可以继续扩展
|
||||
v.SetDefault("unique_id.datacenter_id", 1)
|
||||
v.SetDefault("unique_id.worker_id", 1)
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ func S3UploadFile(c fiber.Ctx) error {
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
folderPath, err := uploadFolderPath(c.FormValue("upload_type"), c.FormValue("family_id"), now)
|
||||
folderPath, err := uploadFolderPath(c.FormValue("upload_type"), c.FormValue("family_id"), c.FormValue("upload_module"), now)
|
||||
if err != nil {
|
||||
return httpx.Fail(c, err.Error())
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func S3CopyFile(c fiber.Ctx) error {
|
||||
return httpx.OK(c, []string{})
|
||||
}
|
||||
|
||||
folderPath := familyDateFolder(req.FamilyID, time.Now())
|
||||
folderPath := familyDateFolder(req.Module, req.FamilyID, time.Now())
|
||||
result := make([]string, 0, len(req.Keys))
|
||||
|
||||
for _, sourceKey := range req.Keys {
|
||||
@@ -128,9 +128,10 @@ func parseFamilyID(value string) (int64, error) {
|
||||
return familyID, nil
|
||||
}
|
||||
|
||||
func familyDateFolder(familyID int64, now time.Time) string {
|
||||
return fmt.Sprintf("%d/%d/%02d/%02d",
|
||||
func familyDateFolder(module string, familyID int64, now time.Time) string {
|
||||
return fmt.Sprintf("business/%d/%s/%d/%02d/%02d",
|
||||
familyID,
|
||||
module,
|
||||
now.Year(),
|
||||
now.Month(),
|
||||
now.Day(),
|
||||
@@ -145,7 +146,7 @@ func avatarDateFolder(now time.Time) string {
|
||||
)
|
||||
}
|
||||
|
||||
func uploadFolderPath(uploadType string, familyIDValue string, now time.Time) (string, error) {
|
||||
func uploadFolderPath(uploadType string, familyIDValue string, module string, now time.Time) (string, error) {
|
||||
if uploadType == "avatar" {
|
||||
return avatarDateFolder(now), nil
|
||||
}
|
||||
@@ -155,5 +156,9 @@ func uploadFolderPath(uploadType string, familyIDValue string, now time.Time) (s
|
||||
return "", fmt.Errorf("family_id不能为空")
|
||||
}
|
||||
|
||||
return familyDateFolder(familyID, now), nil
|
||||
if module == "" {
|
||||
return "", fmt.Errorf("module不能为空")
|
||||
}
|
||||
|
||||
return familyDateFolder(module, familyID, now), nil
|
||||
}
|
||||
@@ -5,6 +5,7 @@ type S3DeleteReq struct {
|
||||
}
|
||||
|
||||
type S3CopyReq struct {
|
||||
Module string `json:"module" validate:"required"`
|
||||
FamilyID int64 `json:"family_id" validate:"required,gt=0"`
|
||||
Keys []string `json:"keys" validate:"required"`
|
||||
}
|
||||
Reference in new issue
Block a user