update vendor

This commit is contained in:
deepzz0
2017-07-08 12:16:15 +08:00
parent 8dc73fd67c
commit 3923bc70f1
63 changed files with 1590 additions and 216 deletions
+10 -16
View File
@@ -8,20 +8,11 @@ import (
)
// CreateTimestampAntileechURL 构建带时间戳防盗链的链接
// host需要加上 "http://" 或 "https://"
// encryptKey 七牛防盗链key
func CreateTimestampAntileechURL(host, fileName string, queryStr url.Values, encryptKey string, durationInSeconds int64) (antileechURL string, err error) {
func CreateTimestampAntileechURL(urlStr string, encryptKey string, durationInSeconds int64) (antileechURL string, err error) {
var urlStr string
if queryStr != nil {
urlStr = fmt.Sprintf("%s/%s?%s", host, fileName, queryStr.Encode())
} else {
urlStr = fmt.Sprintf("%s/%s", host, fileName)
}
u, parseErr := url.Parse(urlStr)
if parseErr != nil {
err = parseErr
u, err := url.Parse(urlStr)
if err != nil {
return
}
@@ -29,13 +20,16 @@ func CreateTimestampAntileechURL(host, fileName string, queryStr url.Values, enc
toSignStr := fmt.Sprintf("%s%s%x", encryptKey, u.EscapedPath(), expireTime)
signedStr := fmt.Sprintf("%x", md5.Sum([]byte(toSignStr)))
q := u.Query()
q := url.Values{}
q.Add("sign", signedStr)
q.Add("t", fmt.Sprintf("%x", expireTime))
u.RawQuery = q.Encode()
antileechURL = fmt.Sprintf("%s://%s%s?%s", u.Scheme, u.Host, u.EscapedPath(), u.Query().Encode())
if u.RawQuery == "" {
antileechURL = u.String() + "?" + q.Encode()
} else {
antileechURL = u.String() + "&" + q.Encode()
}
return
}
+3 -10
View File
@@ -1,15 +1,12 @@
package cdn
import (
"net/url"
"testing"
)
func TestCreateTimestampAntiLeech(t *testing.T) {
type args struct {
host string
fileName string
queryStr url.Values
urlStr string
encryptKey string
durationInSeconds int64
}
@@ -21,11 +18,7 @@ func TestCreateTimestampAntiLeech(t *testing.T) {
{
name: "antileech_1",
args: args{
host: "http://www.abc.com",
fileName: "abc.jpg",
queryStr: url.Values{
"x": {"9"},
},
urlStr: "http://www.abc.com/abc.jpg?stat",
encryptKey: "abc",
durationInSeconds: 20,
},
@@ -34,7 +27,7 @@ func TestCreateTimestampAntiLeech(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_, err := CreateTimestampAntileechURL(tt.args.host, tt.args.fileName, tt.args.queryStr, tt.args.encryptKey, tt.args.durationInSeconds)
_, err := CreateTimestampAntileechURL(tt.args.urlStr, tt.args.encryptKey, tt.args.durationInSeconds)
if (err != nil) != tt.wantErr {
t.Errorf("CreateTimestampAntiLeech() error = %v, wantErr %v", err, tt.wantErr)
return