utils.go
900 字节
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package aliyun
import (
"encoding/base64"
"encoding/json"
"fmt"
"strings"
)
type UploadAddress struct {
Endpoint string
Bucket string
FileName string
}
//@cname 绑定域名
func (up UploadAddress) GetFileUrl(cname string) string {
if len(cname) > 0 {
return fmt.Sprintf("%v%v", cname, up.FileName)
}
if strings.Contains(up.Endpoint, "https") {
return fmt.Sprintf("%v%v.%v/%v", up.Endpoint[:8], up.Bucket, up.Endpoint[8:], up.FileName)
} else if strings.Contains(up.Endpoint, "http") {
return fmt.Sprintf("%v%v.%v/%v", up.Endpoint[:7], up.Bucket, up.Endpoint[7:], up.FileName)
}
return ""
}
//解析UploadAddress
func ParseUploadAddress(uploadAddress string) (up UploadAddress, err error) {
var jsData []byte
jsData, err = base64.StdEncoding.DecodeString(uploadAddress)
if err != nil {
return
}
if err = json.Unmarshal(jsData, &up); err != nil {
return
}
return
}