forked from huaweicloud/huaweicloud-sdk-go
/
doc.go
102 lines (76 loc) · 2.12 KB
/
doc.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
Package objects contains functionality for working with Object Storage
object resources. An object is a resource that represents and contains data
- such as documents, images, and so on. You can also store custom metadata
with an object.
Example to List Objects
containerName := "my_container"
listOpts := objects.ListOpts{
Full: true,
}
allPages, err := objects.List(objectStorageClient, containerName, listOpts).AllPages()
if err != nil {
panic(err)
}
allObjects, err := objects.ExtractInfo(allPages)
if err != nil {
panic(err)
}
for _, object := range allObjects {
fmt.Printf("%+v\n", object)
}
Example to List Object Names
containerName := "my_container"
listOpts := objects.ListOpts{
Full: false,
}
allPages, err := objects.List(objectStorageClient, containerName, listOpts).AllPages()
if err != nil {
panic(err)
}
allObjects, err := objects.ExtractNames(allPages)
if err != nil {
panic(err)
}
for _, object := range allObjects {
fmt.Printf("%+v\n", object)
}
Example to Create an Object
content := "some object content"
objectName := "my_object"
containerName := "my_container"
createOpts := objects.CreateOpts{
ContentType: "text/plain"
Content: strings.NewReader(content),
}
object, err := objects.Create(objectStorageClient, containerName, objectName, createOpts).Extract()
if err != nil {
panic(err)
}
Example to Copy an Object
objectName := "my_object"
containerName := "my_container"
copyOpts := objects.CopyOpts{
Destination: "/newContainer/newObject",
}
object, err := objects.Copy(objectStorageClient, containerName, objectName, copyOpts).Extract()
if err != nil {
panic(err)
}
Example to Delete an Object
objectName := "my_object"
containerName := "my_container"
object, err := objects.Delete(objectStorageClient, containerName, objectName).Extract()
if err != nil {
panic(err)
}
Example to Download an Object's Data
objectName := "my_object"
containerName := "my_container"
object := objects.Download(objectStorageClient, containerName, objectName, nil)
content, err := object.ExtractContent()
if err != nil {
panic(err)
}
*/
package objects