-
Notifications
You must be signed in to change notification settings - Fork 0
/
encryptionput.go
51 lines (45 loc) · 1.48 KB
/
encryptionput.go
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
46
47
48
49
50
51
/**
* Created by GoLand.
* User: 姜伟
* Date: 2020/1/22 0022
* Time: 15:07
*/
package bucket
import (
"github.com/a07061625/gompf/mpf/api/qcloud"
"github.com/a07061625/gompf/mpf/mpconstant/errorcode"
"github.com/a07061625/gompf/mpf/mpconstant/project"
"github.com/a07061625/gompf/mpf/mperr"
"github.com/clbanning/mxj"
"github.com/valyala/fasthttp"
)
// 设置默认加密配置
type encryptionPut struct {
qcloud.BaseCos
configInfo map[string]interface{} // 配置信息
}
func (ep *encryptionPut) SetConfigInfo(configInfo map[string]interface{}) {
if len(configInfo) > 0 {
ep.configInfo = configInfo
} else {
panic(mperr.NewQCloudCos(errorcode.QCloudCosParam, "配置信息不合法", nil))
}
}
func (ep *encryptionPut) CheckData() (*fasthttp.Client, *fasthttp.Request) {
if len(ep.configInfo) == 0 {
panic(mperr.NewQCloudCos(errorcode.QCloudCosParam, "配置信息不能为空", nil))
}
xmlData := mxj.Map(ep.configInfo)
xmlStr, _ := xmlData.Xml("ServerSideEncryptionConfiguration")
reqBody := project.DataPrefixXML + string(xmlStr)
ep.ReqURI = "http://" + ep.ReqHeader["Host"] + ep.ReqUri + "?encryption"
client, req := ep.GetRequest()
req.SetBody([]byte(reqBody))
return client, req
}
func NewEncryptionPut() *encryptionPut {
ep := &encryptionPut{qcloud.NewCos(), make(map[string]interface{})}
ep.ReqMethod = fasthttp.MethodPut
ep.SetParamData("encryption", "")
return ep
}