github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/cdn/v1/domains/results.go (about) 1 package domains 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/chnsz/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 DomainSourcesDetail struct { 63 OriginType string `json:"origin_type"` 64 OriginAddr string `json:"origin_addr"` 65 Priority int `json:"priority"` 66 ObsWebHostingStatus string `json:"obs_web_hosting_status"` 67 HttpPort int `json:"http_port"` 68 HttpsPort int `json:"https_port"` 69 HostName string `json:"host_name"` 70 ObsBucketType string `json:"obs_bucket_type"` 71 } 72 73 // CdnDomainDetail represents a CDN domain by domain name 74 type CdnDomainDetail struct { 75 // the acceleration domain name ID 76 ID string `json:"id"` 77 // the acceleration domain name 78 DomainName string `json:"domain_name"` 79 // the service type, valid values are web, download, video and wholeSite 80 BusinessType string `json:"business_type"` 81 // the status of the acceleration domain name. 82 DomainStatus string `json:"domain_status"` 83 // the CNAME of the acceleration domain name 84 CName string `json:"cname"` 85 // the sources of the domain. 86 Sources []DomainSourcesDetail `json:"sources"` 87 // whether the HTTPS certificate is enabled 88 HttpsStatus int `json:"https_status"` 89 // time when the domain name was created. 90 CreateTime int `json:"create_time"` 91 // time when the domain name was modified. 92 UpdateTime int `json:"update_time"` 93 // whether the domain name is banned. Possible values: 0 (not banned) and 1 (banned). 94 Disabled int `json:"disabled"` 95 // whether the domain name is locked. Possible values: 0 (not locked) and 1 (locked). 96 Locked int `json:"locked"` 97 // service area of the CDN service. Valid values are mainland_china, outside_mainland_china, and global. 98 ServiceArea string `json:"service_area"` 99 } 100 101 type PrivateBucketAccessStatus struct { 102 Status bool `json:"status"` 103 ErrorResp ErrorResp `json:"error"` 104 } 105 106 type ErrorResp struct { 107 ErrorCode string `json:"error_code"` 108 ErrorMsg string `json:"error_msg"` 109 } 110 111 type OriginSources struct { 112 // the domain name or the IP address of the origin server 113 Sources []DomainSources `json:"sources"` 114 } 115 116 type commonResult struct { 117 golangsdk.Result 118 } 119 120 // GetResult is the response from a Get operation. Call its Extract 121 // method to interpret it as a CDN domain. 122 type GetResult struct { 123 commonResult 124 } 125 126 type PrivateBucketAccessResult struct { 127 commonResult 128 } 129 130 func (r PrivateBucketAccessResult) Extract() (*PrivateBucketAccessStatus, error) { 131 var response PrivateBucketAccessStatus 132 err := r.ExtractInto(&response) 133 return &response, err 134 } 135 136 func (r GetResult) Extract() (*CdnDomain, error) { 137 var domain CdnDomain 138 err := r.ExtractInto(&domain) 139 140 // the get request API will response OK, even if errors occurrred. 141 // so we judge domain whether is existing 142 if err == nil && domain.DomainName == "" { 143 err = fmt.Errorf("The CDN domain does not exist.") 144 } 145 return &domain, err 146 } 147 148 func (r GetResult) ExtractInto(v interface{}) error { 149 return r.Result.ExtractIntoStructPtr(v, "domain") 150 } 151 152 type GetDetailResult struct { 153 commonResult 154 } 155 156 func (r GetDetailResult) Extract() (*CdnDomainDetail, error) { 157 var domain CdnDomainDetail 158 err := r.Result.ExtractIntoStructPtr(&domain, "domain") 159 return &domain, err 160 } 161 162 // CreateResult is the result of a Create request. 163 type CreateResult struct { 164 commonResult 165 } 166 167 func (r CreateResult) Extract() (*CdnDomain, error) { 168 var domain CdnDomain 169 err := r.ExtractInto(&domain) 170 171 // the create request API will response OK, even if errors occurrred. 172 // so we judge domain whether is existing 173 if err == nil && domain.DomainStatus != "configuring" { 174 err = fmt.Errorf("%v", r.Body) 175 } 176 return &domain, err 177 } 178 179 func (r CreateResult) ExtractInto(v interface{}) error { 180 return r.Result.ExtractIntoStructPtr(v, "domain") 181 } 182 183 // DeleteResult is the result of a Delete request. Call its ExtractErr method 184 // to determine if the request succeeded or failed. 185 type DeleteResult struct { 186 commonResult 187 } 188 189 func (r DeleteResult) Extract() (*CdnDomain, error) { 190 var domain CdnDomain 191 err := r.ExtractInto(&domain) 192 193 // the delete request API will response OK, even if errors occurrred. 194 // so we judge domain whether is existing 195 if err == nil && domain.DomainStatus != "deleting" { 196 err = fmt.Errorf("%v", r.Body) 197 } 198 return &domain, err 199 } 200 201 func (r DeleteResult) ExtractInto(v interface{}) error { 202 return r.Result.ExtractIntoStructPtr(v, "domain") 203 } 204 205 // EnableResult is the result of a Enable request. 206 type EnableResult struct { 207 commonResult 208 } 209 210 // DisableResult is the result of a Disable request. 211 type DisableResult struct { 212 commonResult 213 } 214 215 // OriginResult is the result of a origin request. Call its ExtractErr method 216 // to determine if the request succeeded or failed. 217 type OriginResult struct { 218 commonResult 219 } 220 221 func (r OriginResult) Extract() (*OriginSources, error) { 222 var origin OriginSources 223 err := r.ExtractInto(&origin) 224 225 return &origin, err 226 } 227 228 func (r OriginResult) ExtractInto(v interface{}) error { 229 return r.Result.ExtractIntoStructPtr(v, "origin") 230 }