瀏覽代碼

update

master
dengbiao 1 天之前
父節點
當前提交
a73dd1e340
共有 2 個檔案被更改,包括 8 行新增55 行删除
  1. +2
    -52
      app/hdl/comm/hdl_comm.go
  2. +6
    -3
      app/hdl/hdl_demo.go

+ 2
- 52
app/hdl/comm/hdl_comm.go 查看文件

@@ -168,54 +168,6 @@ func CommOss(c *gin.Context, args ImgReqUploadReq) {
return
}

cfgMap := make(map[string]string, len(*sysCfgs))
for _, cfg := range *sysCfgs {
cfgMap[cfg.Key] = cfg.Val
}
endpoint := cfgMap[enum2.AliyunOssEndpoint]
bucketName := cfgMap[enum2.AliyunOssBucketName]
ossBucketScheme := cfgMap[enum2.AliyunOssBucketScheme]
accessKeyID := cfgMap[enum2.AliyunOssAccessKeyID]
accessKeySecret := cfgMap[enum2.AliyunOssAccessKeySecret]

// 创建OSSClient实例。
client, err := oss.New(ossBucketScheme+"://"+endpoint, accessKeyID, accessKeySecret)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}

// 获取存储空间。
bucket, err := client.Bucket(bucketName)
if err != nil {
e.OutErr(c, e.ERR, err.Error())
return
}

options := []oss.Option{
oss.ContentType(args.ContentType),
}

signedURL, err := bucket.SignURL(args.FileName, oss.HTTPPut, 60*5, options...)
if err != nil {
e.OutErr(c, e.ERR_AES_ENCODE, err.Error())
return
}

e.OutSuc(c, signedURL, nil)
}
func NewCommOss(c *gin.Context, args ImgReqUploadReq) {
sysCfgDb := sys_cfg.NewSysCfgDb(db.Db)
sysCfgs, err := sysCfgDb.SysCfgGetAll()
if err != nil {
e.OutErr(c, e.ERR_DB_ORM, err.Error())
return
}
if sysCfgs == nil {
e.OutErr(c, e.ERR_CFG_CACHE, nil)
return
}

cfgMap := make(map[string]string, len(*sysCfgs))
for _, cfg := range *sysCfgs {
cfgMap[cfg.Key] = cfg.Val
@@ -226,11 +178,9 @@ func NewCommOss(c *gin.Context, args ImgReqUploadReq) {
accessKeyID := cfgMap[enum2.AliyunOssAccessKeyID]
accessKeySecret := cfgMap[enum2.AliyunOssAccessKeySecret]
if cfg.Prd {
accessKeyID = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID")
accessKeySecret = os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET")
accessKeyID = os.Getenv(enum2.AliyunOssAccessKeyID)
accessKeySecret = os.Getenv(enum2.AliyunOssAccessKeySecret)
}
fmt.Println("ALIBABA_CLOUD_ACCESS_KEY_ID>>>>>>>>", accessKeyID)
fmt.Println("ALIBABA_CLOUD_ACCESS_KEY_SECRET>>>>>>>>", accessKeySecret)

// 创建OSSClient实例。
client, err := oss.New(ossBucketScheme+"://"+endpoint, accessKeyID, accessKeySecret)


+ 6
- 3
app/hdl/hdl_demo.go 查看文件

@@ -2,7 +2,6 @@ package hdl

import (
"applet/app/e"
"applet/app/hdl/comm"
"applet/app/svc"
"github.com/gin-gonic/gin"
)
@@ -18,7 +17,7 @@ import (
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/demo [post]
func Demo(c *gin.Context) {
var args comm.ImgReqUploadReq
var args interface{}
err := c.ShouldBindJSON(&args)
if err != nil {
err = svc.HandleValidateErr(err)
@@ -26,5 +25,9 @@ func Demo(c *gin.Context) {
e.OutErr(c, err1.Code, err1.Error())
return
}
comm.NewCommOss(c, args)

e.OutSuc(c, map[string]interface{}{
"args": args,
}, nil)
return
}

Loading…
取消
儲存