From 91d4a35ac1fd91dca18e70aba88b36b5e81a93b2 Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Wed, 13 Nov 2024 19:34:25 +0800 Subject: [PATCH] update --- app/enum/enum_aliyun_oss.go | 32 +++++++++++++++++ app/hdl/comm/hdl_comm.go | 10 +++--- app/hdl/setCenter/oss/aliyun/hdl_basic.go | 43 ++++++++++++----------- app/md/setCenter/oss/aliyun/md.basic.go | 4 +-- 4 files changed, 61 insertions(+), 28 deletions(-) create mode 100644 app/enum/enum_aliyun_oss.go diff --git a/app/enum/enum_aliyun_oss.go b/app/enum/enum_aliyun_oss.go new file mode 100644 index 0000000..20129da --- /dev/null +++ b/app/enum/enum_aliyun_oss.go @@ -0,0 +1,32 @@ +package enum + +type AliyunOss int32 + +const ( + AliyunOssEndpoint = 1 + AliyunOssBucketName = 2 + AliyunOssBucketScheme = 3 + AliyunOssAccessKeyID = 4 + AliyunOssAccessKeySecret = 5 + AliyunOssDomain = 6 +) + +func (gt AliyunOss) String() string { + switch gt { + case AliyunOssEndpoint: + return "oss_endpoint" + case AliyunOssBucketName: + return "oss_bucket_name" + case AliyunOssBucketScheme: + return "oss_bucket_scheme" + case AliyunOssAccessKeyID: + return "oss_access_key_id" + case AliyunOssAccessKeySecret: + return "oss_access_key_secret" + case AliyunOssDomain: + return "oss_domain" + + default: + return "未知" + } +} diff --git a/app/hdl/comm/hdl_comm.go b/app/hdl/comm/hdl_comm.go index 1c2b68b..af070a8 100644 --- a/app/hdl/comm/hdl_comm.go +++ b/app/hdl/comm/hdl_comm.go @@ -136,11 +136,11 @@ func GetOssUrl(c *gin.Context) { for _, cfg := range *sysCfgs { cfgMap[cfg.Key] = cfg.Val } - endpoint := cfgMap["oss_endpoint"] - bucketName := cfgMap["oss_bucket_name"] - objectName := cfgMap["oss_object_scheme"] - accessKeyID := cfgMap["oss_access_key_id"] - accessKeySecret := cfgMap["oss_access_key_secret"] + endpoint := cfgMap[enum.AliyunOss(enum.AliyunOssEndpoint).String()] + bucketName := cfgMap[enum.AliyunOss(enum.AliyunOssBucketName).String()] + objectName := cfgMap[enum.AliyunOss(enum.AliyunOssBucketScheme).String()] + accessKeyID := cfgMap[enum.AliyunOss(enum.AliyunOssAccessKeyID).String()] + accessKeySecret := cfgMap[enum.AliyunOss(enum.AliyunOssAccessKeySecret).String()] client, err := oss.New(endpoint, accessKeyID, accessKeySecret) if err != nil { diff --git a/app/hdl/setCenter/oss/aliyun/hdl_basic.go b/app/hdl/setCenter/oss/aliyun/hdl_basic.go index 2706c02..25c5011 100644 --- a/app/hdl/setCenter/oss/aliyun/hdl_basic.go +++ b/app/hdl/setCenter/oss/aliyun/hdl_basic.go @@ -3,6 +3,7 @@ package aliyun import ( "applet/app/db" "applet/app/e" + "applet/app/enum" md "applet/app/md/setCenter/oss/aliyun" "applet/app/utils/cache" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" @@ -31,41 +32,41 @@ func GetBasic(c *gin.Context) { for _, cfg := range *sysCfg { cfgMap[cfg.Key] = cfg.Val } - endpoint, ok := cfgMap["oss_endpoint"] + endpoint, ok := cfgMap[enum.AliyunOss(enum.AliyunOssEndpoint).String()] if !ok { - sysCfgDb.SysCfgInsert("oss_endpoint", "", "oss地域节点") + sysCfgDb.SysCfgInsert(enum.AliyunOss(enum.AliyunOssEndpoint).String(), "", "oss地域节点") endpoint = "" } - bucketName, ok := cfgMap["oss_bucket_name"] + bucketName, ok := cfgMap[enum.AliyunOss(enum.AliyunOssBucketName).String()] if !ok { - sysCfgDb.SysCfgInsert("oss_bucket_name", "", "oss存储桶名称") + sysCfgDb.SysCfgInsert(enum.AliyunOss(enum.AliyunOssBucketName).String(), "", "oss存储桶名称") bucketName = "" } - objectScheme, ok := cfgMap["oss_object_scheme"] + bucketScheme, ok := cfgMap[enum.AliyunOss(enum.AliyunOssBucketScheme).String()] if !ok { - sysCfgDb.SysCfgInsert("oss_object_scheme", "", "oss上传方式") - objectScheme = "" + sysCfgDb.SysCfgInsert(enum.AliyunOss(enum.AliyunOssBucketScheme).String(), "", "oss上传方式") + bucketScheme = "" } - accessKeyID, ok := cfgMap["oss_access_key_id"] + accessKeyID, ok := cfgMap[enum.AliyunOss(enum.AliyunOssAccessKeyID).String()] if !ok { - sysCfgDb.SysCfgInsert("oss_access_key_id", "", "oss访问秘钥id") + sysCfgDb.SysCfgInsert(enum.AliyunOss(enum.AliyunOssAccessKeyID).String(), "", "oss访问秘钥id") accessKeyID = "" } - accessKeySecret, ok := cfgMap["oss_access_key_secret"] + accessKeySecret, ok := cfgMap[enum.AliyunOss(enum.AliyunOssAccessKeySecret).String()] if !ok { - sysCfgDb.SysCfgInsert("oss_access_key_secret", "", "oss访问秘钥") + sysCfgDb.SysCfgInsert(enum.AliyunOss(enum.AliyunOssAccessKeySecret).String(), "", "oss访问秘钥") accessKeySecret = "" } - domain, ok := cfgMap["oss_object_domain"] + domain, ok := cfgMap[enum.AliyunOss(enum.AliyunOssDomain).String()] if !ok { - sysCfgDb.SysCfgInsert("oss_object_domain", "", "oss域名") + sysCfgDb.SysCfgInsert(enum.AliyunOss(enum.AliyunOssDomain).String(), "", "oss域名") domain = "" } resp := md.GetBasicResp{ OssEndpoint: endpoint, OssBucketName: bucketName, - OssObjectScheme: objectScheme, + OssBucketScheme: bucketScheme, OssAccessKeyId: accessKeyID, OssAccessKeySecret: accessKeySecret, OssObjectDomain: domain, @@ -96,22 +97,22 @@ func SetBasic(c *gin.Context) { cfgDb := implement.NewSysCfgDb(db.Db, redisConn) if req.OssAccessKeyId != "" { - cfgDb.SysCfgUpdate("oss_access_key_id", req.OssAccessKeyId) + cfgDb.SysCfgUpdate(enum.AliyunOss(enum.AliyunOssAccessKeyID).String(), req.OssAccessKeyId) } if req.OssAccessKeySecret != "" { - cfgDb.SysCfgUpdate("oss_access_key_secret", req.OssAccessKeySecret) + cfgDb.SysCfgUpdate(enum.AliyunOss(enum.AliyunOssAccessKeySecret).String(), req.OssAccessKeySecret) } - if req.OssObjectScheme != "" { - cfgDb.SysCfgUpdate("oss_object_scheme", req.OssObjectScheme) + if req.OssBucketScheme != "" { + cfgDb.SysCfgUpdate(enum.AliyunOss(enum.AliyunOssBucketScheme).String(), req.OssBucketScheme) } if req.OssObjectDomain != "" { - cfgDb.SysCfgUpdate("oss_object_domain", req.OssObjectDomain) + cfgDb.SysCfgUpdate(enum.AliyunOss(enum.AliyunOssDomain).String(), req.OssObjectDomain) } if req.OssBucketName != "" { - cfgDb.SysCfgUpdate("oss_bucket_name", req.OssBucketName) + cfgDb.SysCfgUpdate(enum.AliyunOss(enum.AliyunOssBucketName).String(), req.OssBucketName) } if req.OssEndpoint != "" { - cfgDb.SysCfgUpdate("oss_endpoint", req.OssEndpoint) + cfgDb.SysCfgUpdate(enum.AliyunOss(enum.AliyunOssEndpoint).String(), req.OssEndpoint) } e.OutSuc(c, "success", nil) } diff --git a/app/md/setCenter/oss/aliyun/md.basic.go b/app/md/setCenter/oss/aliyun/md.basic.go index 0f44e19..bba79cc 100644 --- a/app/md/setCenter/oss/aliyun/md.basic.go +++ b/app/md/setCenter/oss/aliyun/md.basic.go @@ -3,7 +3,7 @@ package md type GetBasicResp struct { OssEndpoint string `json:"oss_endpoint" example:"oss地域节点"` OssBucketName string `json:"oss_bucket_name" example:"oss存储桶名称"` - OssObjectScheme string `json:"oss_object_scheme" example:"oss上传方式"` + OssBucketScheme string `json:"oss_bucket_scheme" example:"oss上传方式"` OssAccessKeyId string `json:"oss_access_key_id" example:"oss访问秘钥id"` OssAccessKeySecret string `json:"oss_access_key_secret" example:"oss访问秘钥"` OssObjectDomain string `json:"oss_object_domain" example:"oss域名"` @@ -12,7 +12,7 @@ type GetBasicResp struct { type SetBasicReq struct { OssEndpoint string `json:"oss_endpoint" example:"oss地域节点"` OssBucketName string `json:"oss_bucket_name" example:"oss存储桶名称"` - OssObjectScheme string `json:"oss_object_scheme" example:"oss上传方式"` + OssBucketScheme string `json:"oss_bucket_scheme" example:"oss上传方式"` OssAccessKeyId string `json:"oss_access_key_id" example:"oss访问秘钥id"` OssAccessKeySecret string `json:"oss_access_key_secret" example:"oss访问秘钥"` OssObjectDomain string `json:"oss_object_domain" example:"oss域名"`