forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
organization_resource.go
48 lines (39 loc) · 1011 Bytes
/
organization_resource.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
package resources
import (
"encoding/json"
)
// Organization represents a Cloud Controller V3 Organization.
type Organization struct {
// GUID is the unique organization identifier.
GUID string `json:"guid,omitempty"`
// Name is the name of the organization.
Name string `json:"name"`
// QuotaGUID is the GUID of the organization Quota applied to this Organization
QuotaGUID string `json:"-"`
// Metadata is used for custom tagging of API resources
Metadata *Metadata `json:"metadata,omitempty"`
}
func (org *Organization) UnmarshalJSON(data []byte) error {
type alias Organization
var aliasOrg alias
err := json.Unmarshal(data, &aliasOrg)
if err != nil {
return err
}
*org = Organization(aliasOrg)
remainingFields := new(struct {
Relationships struct {
Quota struct {
Data struct {
GUID string
}
}
}
})
err = json.Unmarshal(data, &remainingFields)
if err != nil {
return err
}
org.QuotaGUID = remainingFields.Relationships.Quota.Data.GUID
return nil
}