github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/cdn/v1/domains/results.go (about) 1 package domains 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/huaweicloud/golangsdk" 8 ) 9 10 // sources 11 type DomainSources struct { 12 DomainID string `json:"domain_id"` 13 IporDomain string `json:"ip_or_domain"` 14 OriginType string `json:"origin_type"` 15 ActiveStandby int `json:"active_standby"` 16 } 17 18 // domain_origin_host 19 type DomainOriginHost struct { 20 DomainID string `json:"domain_id"` 21 OriginHostType string `json:"origin_host_type"` 22 CustomizeDomain string `json:"customize_domain"` 23 } 24 25 // CdnDomain represents a CDN domain 26 type CdnDomain struct { 27 // the acceleration domain name ID 28 ID string `json:"id"` 29 // the acceleration domain name 30 DomainName string `json:"domain_name"` 31 // the service type, valid values are web, download, video 32 BusinessType string `json:"business_type"` 33 // the domain ID of the domain name's owner 34 UserDomainId string `json:"user_domain_id"` 35 // the status of the acceleration domain name. 36 DomainStatus string `json:"domain_status"` 37 // the CNAME of the acceleration domain name 38 CName string `json:"cname"` 39 // the domain name or the IP address of the origin server 40 Sources []DomainSources `json:"sources"` 41 // the configuration information of the retrieval host 42 OriginHost DomainOriginHost `json:"domain_origin_host"` 43 // whether the HTTPS certificate is enabled 44 HttpsStatus *int `json:"https_status"` 45 // whether the status is disabled 46 Disabled *int `json:"disabled"` 47 // whether the status is locked 48 Locked *int `json:"locked"` 49 // the area covered by the accelecration service 50 ServiceArea string `json:"service_area"` 51 // whether range-based retrieval is enabled 52 RangeStatus string `json:"range_status"` 53 // a thrid-party CDN 54 ThridPartCDN string `json:"third_part_cdn"` 55 // the id of enterprise project 56 EnterpriseProjectId string `json:"enterprise_project_id"` 57 58 CreateTime time.Time `json:"-"` 59 ModifyTime time.Time `json:"-"` 60 } 61 62 type OriginSources struct { 63 // the domain name or the IP address of the origin server 64 Sources []DomainSources `json:"sources"` 65 } 66 67 type commonResult struct { 68 golangsdk.Result 69 } 70 71 // GetResult is the response from a Get operation. Call its Extract 72 // method to interpret it as a CDN domain. 73 type GetResult struct { 74 commonResult 75 } 76 77 func (r GetResult) Extract() (*CdnDomain, error) { 78 var domain CdnDomain 79 err := r.ExtractInto(&domain) 80 81 // the get request API will response OK, even if errors occurrred. 82 // so we judge domain whether is existing 83 if err == nil && domain.DomainName == "" { 84 err = fmt.Errorf("The CDN domain does not exist.") 85 } 86 return &domain, err 87 } 88 89 func (r GetResult) ExtractInto(v interface{}) error { 90 return r.Result.ExtractIntoStructPtr(v, "domain") 91 } 92 93 // CreateResult is the result of a Create request. 94 type CreateResult struct { 95 commonResult 96 } 97 98 func (r CreateResult) Extract() (*CdnDomain, error) { 99 var domain CdnDomain 100 err := r.ExtractInto(&domain) 101 102 // the create request API will response OK, even if errors occurrred. 103 // so we judge domain whether is existing 104 if err == nil && domain.DomainStatus != "configuring" { 105 err = fmt.Errorf("%v", r.Body) 106 } 107 return &domain, err 108 } 109 110 func (r CreateResult) ExtractInto(v interface{}) error { 111 return r.Result.ExtractIntoStructPtr(v, "domain") 112 } 113 114 // DeleteResult is the result of a Delete request. Call its ExtractErr method 115 // to determine if the request succeeded or failed. 116 type DeleteResult struct { 117 commonResult 118 } 119 120 func (r DeleteResult) Extract() (*CdnDomain, error) { 121 var domain CdnDomain 122 err := r.ExtractInto(&domain) 123 124 // the delete request API will response OK, even if errors occurrred. 125 // so we judge domain whether is existing 126 if err == nil && domain.DomainStatus != "deleting" { 127 err = fmt.Errorf("%v", r.Body) 128 } 129 return &domain, err 130 } 131 132 func (r DeleteResult) ExtractInto(v interface{}) error { 133 return r.Result.ExtractIntoStructPtr(v, "domain") 134 } 135 136 // EnableResult is the result of a Enable request. 137 type EnableResult struct { 138 commonResult 139 } 140 141 // DisableResult is the result of a Disable request. 142 type DisableResult struct { 143 commonResult 144 } 145 146 // OriginResult is the result of a origin request. Call its ExtractErr method 147 // to determine if the request succeeded or failed. 148 type OriginResult struct { 149 commonResult 150 } 151 152 func (r OriginResult) Extract() (*OriginSources, error) { 153 var origin OriginSources 154 err := r.ExtractInto(&origin) 155 156 return &origin, err 157 } 158 159 func (r OriginResult) ExtractInto(v interface{}) error { 160 return r.Result.ExtractIntoStructPtr(v, "origin") 161 }