-
Notifications
You must be signed in to change notification settings - Fork 0
/
inventoryput.go
70 lines (62 loc) · 2.12 KB
/
inventoryput.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
* Created by GoLand.
* User: 姜伟
* Date: 2020/1/22 0022
* Time: 14:14
*/
package bucket
import (
"encoding/base64"
"github.com/a07061625/gompf/mpf"
"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 inventoryPut struct {
qcloud.BaseCos
taskId string // 任务ID
taskInfo map[string]interface{} // 任务信息
}
func (ip *inventoryPut) SetTaskId(taskId string) {
if len(taskId) > 0 {
ip.SetParamData("id", taskId)
ip.taskId = taskId
} else {
panic(mperr.NewQCloudCos(errorcode.QCloudCosParam, "任务ID不合法", nil))
}
}
func (ip *inventoryPut) SetTaskInfo(taskInfo map[string]interface{}) {
if len(taskInfo) > 0 {
ip.taskInfo = taskInfo
} else {
panic(mperr.NewQCloudCos(errorcode.QCloudCosParam, "任务信息不合法", nil))
}
}
func (ip *inventoryPut) CheckData() (*fasthttp.Client, *fasthttp.Request) {
if len(ip.taskId) == 0 {
panic(mperr.NewQCloudCos(errorcode.QCloudCosParam, "任务ID不能为空", nil))
}
if len(ip.taskInfo) == 0 {
panic(mperr.NewQCloudCos(errorcode.QCloudCosParam, "任务信息不能为空", nil))
}
xmlData := mxj.Map(ip.taskInfo)
xmlStr, _ := xmlData.Xml("InventoryConfiguration")
reqBody := project.DataPrefixXML + string(xmlStr)
encodeStr := base64.StdEncoding.EncodeToString([]byte(reqBody))
ip.SetHeaderData("Content-MD5", mpf.HashMd5(encodeStr, ""))
delete(ip.ReqData, "inventory")
ip.ReqURI = "http://" + ip.ReqHeader["Host"] + ip.ReqUri + "?inventory&" + mpf.HTTPCreateParams(ip.ReqData, "none", 1)
client, req := ip.GetRequest()
req.SetBody([]byte(reqBody))
return client, req
}
func NewInventoryPut() *inventoryPut {
ip := &inventoryPut{qcloud.NewCos(), "", make(map[string]interface{})}
ip.ReqMethod = fasthttp.MethodPut
ip.SetParamData("inventory", "")
return ip
}