Browse Source

add oss format

master
shenjiachi 2 days ago
parent
commit
050246e217
2 changed files with 18 additions and 1 deletions
  1. +6
    -0
      enum/sys_cfg.go
  2. +12
    -1
      svc/svc_file_img_format.go

+ 6
- 0
enum/sys_cfg.go View File

@@ -50,6 +50,8 @@ const (
AliyunOssAccessKeySecret = "oss_access_key_secret"
AliyunOssDomain = "oss_domain"
AliyunOptions = "oss_options"
AliyunOssAccountId = "oss_account_id"
AliyunOssRoleName = "oss_role_name"
)

func (gt AliyunOss) String() string {
@@ -68,6 +70,10 @@ func (gt AliyunOss) String() string {
return "oss域名"
case AliyunOptions:
return "文件上传类型"
case AliyunOssAccountId:
return "阿里云账户id"
case AliyunOssRoleName:
return "oss RAM角色名称"

default:
return "未知"


+ 12
- 1
svc/svc_file_img_format.go View File

@@ -30,6 +30,17 @@ func ImageFormatWithBucketNew(scheme, domain, name string) string {
return name
}

name = strings.ReplaceAll(name, "{{host}}", "")
name = strings.ReplaceAll(name, "{{tempHost}}", "")
return fmt.Sprintf("%s://%s/%s", scheme, domain, name)
}

// ImageFormatWithBucketForDataInfo is 格式化成oss 域名 (只格式化内容中的 url)
func ImageFormatWithBucketForDataInfo(scheme, domain, name string) string {
if strings.Contains(name, "http") {
return name
}

prefix := fmt.Sprintf("%s://%s/", scheme, domain)
name = strings.ReplaceAll(name, "{{tempHost}}", prefix)
return name
}

Loading…
Cancel
Save