Browse Source

update

master
dengbiao 1 day ago
parent
commit
441d9a377e
3 changed files with 62 additions and 6 deletions
  1. +56
    -0
      app/hdl/comm/hdl_comm.go
  2. +3
    -6
      app/hdl/hdl_demo.go
  3. +3
    -0
      k8s/container_prd.yaml

+ 56
- 0
app/hdl/comm/hdl_comm.go View File

@@ -1,6 +1,7 @@
package comm

import (
"applet/app/cfg"
"applet/app/db"
"applet/app/e"
"applet/app/enum"
@@ -15,6 +16,7 @@ import (
sts20150401 "github.com/alibabacloud-go/sts-20150401/v2/client"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
"github.com/gin-gonic/gin"
"os"
"strings"
)

@@ -202,6 +204,60 @@ func CommOss(c *gin.Context, args ImgReqUploadReq) {

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
}
endpoint := cfgMap[enum2.AliyunOssEndpoint]
bucketName := cfgMap[enum2.AliyunOssBucketName]
ossBucketScheme := cfgMap[enum2.AliyunOssBucketScheme]
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")
}
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)
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)
}

const STSVoucherRedisKey = "STS_Voucher_Cache_Key"



+ 3
- 6
app/hdl/hdl_demo.go View File

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

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

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

+ 3
- 0
k8s/container_prd.yaml View File

@@ -51,6 +51,9 @@ spec:
- name: egg-admin-container
# 镜像地址(提前打包好并推送的镜像仓库)
image: 'registry.cn-shenzhen.aliyuncs.com/fnuoos-prd/egg-admin:20241205-01'
envFrom:
- secretRef:
name: alibaba-cloud-credentials
ports:
- name: egg-admin-4010
# 容器端口号(注意与golang web server启动的端口一致)


Loading…
Cancel
Save