github.com/sleungcy-sap/cli@v7.1.0+incompatible/resources/organization_resource.go (about)

     1  package resources
     2  
     3  import (
     4  	"encoding/json"
     5  )
     6  
     7  // Organization represents a Cloud Controller V3 Organization.
     8  type Organization struct {
     9  	// GUID is the unique organization identifier.
    10  	GUID string `json:"guid,omitempty"`
    11  	// Name is the name of the organization.
    12  	Name string `json:"name"`
    13  	// QuotaGUID is the GUID of the organization Quota applied to this Organization
    14  	QuotaGUID string `json:"-"`
    15  
    16  	// Metadata is used for custom tagging of API resources
    17  	Metadata *Metadata `json:"metadata,omitempty"`
    18  }
    19  
    20  func (org *Organization) UnmarshalJSON(data []byte) error {
    21  	type alias Organization
    22  	var aliasOrg alias
    23  	err := json.Unmarshal(data, &aliasOrg)
    24  	if err != nil {
    25  		return err
    26  	}
    27  
    28  	*org = Organization(aliasOrg)
    29  
    30  	remainingFields := new(struct {
    31  		Relationships struct {
    32  			Quota struct {
    33  				Data struct {
    34  					GUID string
    35  				}
    36  			}
    37  		}
    38  	})
    39  
    40  	err = json.Unmarshal(data, &remainingFields)
    41  	if err != nil {
    42  		return err
    43  	}
    44  
    45  	org.QuotaGUID = remainingFields.Relationships.Quota.Data.GUID
    46  
    47  	return nil
    48  }