-
Notifications
You must be signed in to change notification settings - Fork 3
/
Resources.go
57 lines (51 loc) · 1.25 KB
/
Resources.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
package resources
import (
"encoding/json"
"fmt"
"strings"
)
type Resources struct {
ResourceDetails []*ResourceDetail `json:"resourceDetails"`
}
func (r *Resources) ToString() string {
str := fmt.Sprintf("Resources{resourceDetails=%s}", ListResourceDetailToString(r.ResourceDetails))
return str
}
func (r *Resources) ParseSelfFromJson(valueBytes []byte) {
//r.ResourceDetails = make([]*ResourceDetail, 0)
//m := make(map[string]interface{})
//err := json.Unmarshal(valueBytes, &m)
//if err != nil {
// return
//}
//details, ok := m["resourceDetails"].([]interface{})
//if !ok {
// return
//}
//for _, obj := range details {
// objBytes, errr := json.Marshal(obj)
// if errr != nil {
// continue
// }
// detail := new(ResourceDetail)
// errr = json.Unmarshal(objBytes, detail)
// if errr != nil {
// continue
// }
// r.ResourceDetails = append(r.ResourceDetails, detail)
//}
err := json.Unmarshal(valueBytes, r)
if err != nil {
r.ResourceDetails = make([]*ResourceDetail, 0)
}
}
func ListResourceDetailToString(resourcesDetails []*ResourceDetail) string {
str := "["
for i := 0; i < len(resourcesDetails); i++ {
str += resourcesDetails[i].ToString()
str += ", "
}
str = strings.TrimSuffix(str, ", ")
str += "]"
return str
}