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
41
42
43
44
45
package common
import (
"crypto/md5"
"encoding/base64"
"fmt"
log "github.com/sirupsen/logrus"
"os"
"path/filepath"
"strings"
"time"
)
func HTTPGMTDate() string {
GmtDateLayout := "Mon, 02 Jan 2006 15:04:05 GMT"
return time.Now().UTC().Format(GmtDateLayout)
}
func MakeSignature(key, date string) string {
s := strings.Join([]string{key, date}, "\n")
return Base64Encode(MD5Encode([]byte(s)))
}
func Base64Encode(s string) string {
return base64.StdEncoding.EncodeToString([]byte(s))
}
func MD5Encode(b []byte) string {
return fmt.Sprintf("%x", md5.Sum(b))
}
func MakeSureDirExit(filePath string) {
dirPath := filepath.Dir(filePath)
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
err = os.MkdirAll(dirPath, os.ModePerm)
if err != nil {
log.Info("could not create dir path:", dirPath)
os.Exit(1)
}
log.Info("create dir path:", dirPath)
return
}
log.Info("dir path exits:", dirPath)
}