-
Notifications
You must be signed in to change notification settings - Fork 0
/
Content.go
54 lines (42 loc) · 1.44 KB
/
Content.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
package tm1go
type Content struct {
OdataType string `json:"@odata.type,omitempty"`
ID string `json:"ID,omitempty"`
Name string `json:"Name,omitempty"`
Size int `json:"Size,omitempty"`
LastUpdated string `json:"LastUpdated,omitempty"`
MediaContentType string `json:"Content@odata.mediaContentType,omitempty"`
Contents []Content `json:"Contents,omitempty"`
}
func extractNamesFromContents(contents []Content, parentPath string) []string {
var names []string
for _, content := range contents {
currentPath := content.Name
if parentPath != "" {
currentPath = parentPath + "/" + content.Name
}
names = append(names, currentPath)
if len(content.Contents) > 0 {
names = append(names, extractNamesFromContents(content.Contents, currentPath)...)
}
}
return names
}
func ExtractNamesFromContents(contents []Content) []string {
return extractNamesFromContents(contents, "")
}
func extractNamesFromContent(content Content, parentPath string) []string {
var names []string
currentPath := content.Name
if parentPath != "" {
currentPath = parentPath + "/" + content.Name
}
names = append(names, currentPath)
for _, nestedContent := range content.Contents {
names = append(names, extractNamesFromContent(nestedContent, currentPath)...)
}
return names
}
func ExtractNamesFromContent(content Content) []string {
return extractNamesFromContent(content, "")
}