forked from galaxydi/go-loghub
-
Notifications
You must be signed in to change notification settings - Fork 110
/
subresource_tags.go
60 lines (55 loc) · 1.36 KB
/
subresource_tags.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
package main
import (
"fmt"
sls "github.com/aliyun/aliyun-log-go-sdk"
"github.com/aliyun/aliyun-log-go-sdk/example/util"
)
func main() {
fmt.Println("Tag Resource")
resouceId := sls.GenResourceId(util.ProjectName, util.LogStoreName)
resourceTags := sls.NewResourceTags("logstore", resouceId, []sls.ResourceTag{
{
Key: "the-tag",
Value: "aliyun-log-go-sdk",
},
{
Key: "the-tag-2",
Value: "aliyun log go sdk",
},
})
err := util.Client.TagResources(util.ProjectName, resourceTags)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Tag Resource success")
}
listTags("logstore")
fmt.Println("UnTag Resource")
resouceUnTags := sls.NewResourceUnTags("logstore", resouceId, []string{"the-tag"})
err = util.Client.UnTagResources(util.ProjectName, resouceUnTags)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("UnTag Resource success")
}
listTags("logstore")
}
func listTags(resourceType string) {
fmt.Println("tag list: ")
respTags, _, err := util.Client.ListTagResources(
util.ProjectName,
resourceType,
[]string{sls.GenResourceId(util.ProjectName, util.LogStoreName)},
[]sls.ResourceFilterTag{},
"")
if err != nil {
panic(err)
}
for _, tag := range respTags {
fmt.Printf(" resourceType : %s, resourceID : %s, tagKey : %s, tagValue : %s\n",
tag.ResourceType,
tag.ResourceID,
tag.TagKey,
tag.TagValue)
}
}