forked from galaxydi/go-loghub
-
Notifications
You must be signed in to change notification settings - Fork 110
/
resource_tags.go
68 lines (60 loc) · 1.43 KB
/
resource_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
61
62
63
64
65
66
67
68
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")
projectTags := sls.NewProjectTags(util.ProjectName, []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, projectTags)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("Tag Resource success")
}
listAllTags()
fmt.Println("UnTag Resource")
projectUnTags := sls.NewProjectUnTags(util.ProjectName, []string{"the-tag"})
err = util.Client.UnTagResources(util.ProjectName, projectUnTags)
if err != nil {
fmt.Println(err)
} else {
fmt.Println("UnTag Resource success")
}
listAllTags()
}
func getStringPtr(data string) *string {
return &data
}
// List all the projects below this region.
func listAllTags() {
var nextToken string
fmt.Println("tag list: ")
for {
respTags, respNextToken, err := util.Client.ListTagResources(util.ProjectName, "project", []string{util.ProjectName}, []sls.ResourceFilterTag{}, nextToken)
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)
}
nextToken = respNextToken
if nextToken == "" {
break
}
}
}