github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/api/cloudcontroller/ccv2/domain.go (about) 1 package ccv2 2 3 import ( 4 "encoding/json" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller" 7 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/internal" 8 ) 9 10 // Domain represents a Cloud Controller Domain. 11 type Domain struct { 12 GUID string 13 Name string 14 } 15 16 // UnmarshalJSON helps unmarshal a Cloud Controller Domain response. 17 func (domain *Domain) UnmarshalJSON(data []byte) error { 18 var ccDomain struct { 19 Metadata internal.Metadata `json:"metadata"` 20 Entity struct { 21 Name string `json:"name"` 22 } `json:"entity"` 23 } 24 if err := json.Unmarshal(data, &ccDomain); err != nil { 25 return err 26 } 27 28 domain.GUID = ccDomain.Metadata.GUID 29 domain.Name = ccDomain.Entity.Name 30 return nil 31 } 32 33 // GetSharedDomain returns the Shared Domain associated with the provided 34 // Domain GUID. 35 func (client *Client) GetSharedDomain(domainGUID string) (Domain, Warnings, error) { 36 request, err := client.newHTTPRequest(requestOptions{ 37 RequestName: internal.SharedDomainRequest, 38 URIParams: map[string]string{"shared_domain_guid": domainGUID}, 39 }) 40 if err != nil { 41 return Domain{}, nil, err 42 } 43 44 var domain Domain 45 response := cloudcontroller.Response{ 46 Result: &domain, 47 } 48 49 err = client.connection.Make(request, &response) 50 if err != nil { 51 return Domain{}, response.Warnings, err 52 } 53 54 return domain, response.Warnings, nil 55 } 56 57 // GetPrivateDomain returns the Private Domain associated with the provided 58 // Domain GUID. 59 func (client *Client) GetPrivateDomain(domainGUID string) (Domain, Warnings, error) { 60 request, err := client.newHTTPRequest(requestOptions{ 61 RequestName: internal.PrivateDomainRequest, 62 URIParams: map[string]string{"private_domain_guid": domainGUID}, 63 }) 64 if err != nil { 65 return Domain{}, nil, err 66 } 67 68 var domain Domain 69 response := cloudcontroller.Response{ 70 Result: &domain, 71 } 72 73 err = client.connection.Make(request, &response) 74 if err != nil { 75 return Domain{}, response.Warnings, err 76 } 77 78 return domain, response.Warnings, nil 79 }