20260719215738

This commit is contained in:
oneao committed 2026-07-19 21:57:40 +08:00
1 parent 35aa108a34
commit cda7f16d3a
116 files changed
+11826 -3669

No files matched your search

Binary file not shown.
+5
View File
@@ -0,0 +1,5 @@
@echo off
set GOOS=linux
set GOARCH=amd64
go build -o app-go .\cmd\app
echo Build done: app-go
+5 -5
View File
@@ -2,11 +2,11 @@ app:
port: 8087
base_url: ""
postgres:
host: 117.72.182.135
host: 118.89.70.199
port: 5432
user: postgres
password: zhang520..
dbname: allapp
dbname: app-dev
timezone: Asia/Shanghai
max_open_conns: 10
max_idle_conns: 5
@@ -14,7 +14,7 @@ postgres:
ssl_mode: false
aws_s3:
region: us-east-1
access_key: 2c0sZEpPQyCVhoLGNzHS
secret_key: fRbcQPEhU8B0C3On4qIoJ19w5vXxTFD26LlAiae7
access_key: fUkOMAzaBW7HV5wq4BSQ
secret_key: sCIWI5e4c5gHNGqrNCsTjvIkcWK1W8EXD7feUdJR
endpoint: http://118.89.70.199:9000
bucket: test
bucket: app-dev
+20
View File
@@ -0,0 +1,20 @@
app:
port: 8080
base_url: /app
postgres:
host: 118.89.70.199
port: 5432
user: postgres
password: zhang520..
dbname: app-prod
timezone: Asia/Shanghai
max_open_conns: 20
max_idle_conns: 10
conn_max_lifetime: 30m
ssl_mode: false
aws_s3:
region: us-east-1
access_key: fUkOMAzaBW7HV5wq4BSQ
secret_key: sCIWI5e4c5gHNGqrNCsTjvIkcWK1W8EXD7feUdJR
endpoint: http://118.89.70.199:9000
bucket: app-prod
+1 -2
View File
@@ -1,6 +1,5 @@
app:
name: allapp
port: 8080
name: 窝织
base_url: /app
wechat:
app_id: wxdab3e21a1f7e392f
+1 -7
View File
@@ -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)
}
+11 -6
View File
@@ -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
}
+1
View File
@@ -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"`
}