百度智能云

All Product Document

          CDN

          Domain Name Operation Interface

          Query Domain Name List ListDomains

          Query the accelerated domain names under the user account.

          marker := ""                                           
          cli := GetDefaultClient()                          
          domains, nextMarker, err := cli.ListDomains(marker)    
          fmt.Printf("domains:%+v\n", domains)                   
          fmt.Printf("nextMarker:%+v\n", nextMarker)             
          fmt.Printf("err:%+v\n", err)                           

          The marker parameter means querying the domain name list from the index represented by this string. When it is empty, it means starting from the beginning. At present, the server processing page size is a very large number, so when it is used, set the marker to be empty. nextMarker returned by ListDomains represents the index of the next domain name list. When it is empty, it means getting all domain name lists after marker; when it is not empty, it can be passed to the ListDomains parameter. domains is a string slice, representing domain name list data, such as: [ "1.baidu.com ", "2.baidu.com "].

          Query all Domain Names under the Username GetDomainStatus

          Query all domain names and domain name status under the username, and query the domain names which are in the specific status.

          cli := client.GetDefaultClient()   
          status := "ALL" 
          domainStatus, err := cli.GetDomainStatus(status, "")     
          fmt.Printf("domainStatus:%+v\n", domainStatus)          
          fmt.Printf("err:%+v\n", err)                            

          status means the domain name status. If it isALL, it means querying domain names in all status. RUNNING means querying domain names that have been accelerated. STOPPED means querying domain names for which acceleration is stopped, and OPERATING means querying operating domain names. domainStatus is an object in DomainStatus type, as shown below:

          Field Type Description
          Domain string Domain name, such as www.baidu.com
          Status string State of domain name, with the legal values ‘RUNNING’, ‘STOPPED’ and ‘OPERATING’.`

          Example data of domainStatus: [{"Domain":"1.baidu.com", "Status":"RUNNING"}, {"Domain":"2.baidu.com", "Status":"STOPPED"}]

          Check Whether the Domain Name can be Added IsValidDomain

          Query whether CDN acceleration can be used in a specific domain name. A domain name which can be added shall be a valid domain name and cannot be added repeatedly. It shall be filed by ICP.

          cli := client.GetDefaultClient()           
          testDomain := "test_go_sdk.baidu.com" 
          domainValidInfo, err := cli.IsValidDomain(testDomain)  
          fmt.Printf("domainValidInfo:%+v\n", domainValidInfo)                
          fmt.Printf("err:%+v\n", err)                                        

          testDomain is the domain name to be tested. domainValidInfo is an object in DomainValidInfo type, and it represents detailed information about whether it can be added.

          Field Type Description
          Domain string Domain name, such as www.baidu.com
          IsValid bool true means the domain name can be added, and false means the domain name cannot be added.
          Message string When IsValid is false, it indicates the reason why the domain name cannot be added; when IsValid is true, it is empty.

          Create an Accelerated Domain Name Interface CreateDomain

          Add an acceleration domain name under the username, and the domain name must return true when calling IsValidDomain. You have to set an origin server for creating an accelerated domain name.

          cli := client.GetDefaultClient() 
          domainCreatedInfo, err := cli.CreateDomain("test_go_sdk.baidu.com", &api.OriginInit{ 
          	 Origin: []api.OriginPeer{ 
          	 	 { 
          	 	 	 Peer:      "1.1.1.1", 
          	 	 	 Host:      "www.baidu.com", 
          	 	 	 Backup:    true, 
          	 	 	 Follow302: true, 
          	 	 }, 
          	 	 { 
          	 	 	 Peer:      "http://2.2.2.2", 
          	 	 	 Host:      "www.baidu.com", 
          	 	 	 Backup:    false, 
          	 	 	 Follow302: true, 
          	 	 }, 
          	 }, 
          	 DefaultHost: "www.baidu.com", 
          	 Form:        "default", 
          }) 
          fmt.Printf("domainCreatedInfo:%+v\n", domainCreatedInfo) 
          fmt.Printf("err:%+v\n", err) 

          api.OriginPeer represents an origin server. api.OriginInit represents the origin server configuration for this accelerated domain name, including one or more origin servers and a default member host, represented by DefaultHost. Form represents the acceleration service type, and the default is default. Other optional service types are image for small image files, download for large file downloads, media for streaming media on-demand, and dynamic for dynamic and static acceleration. The structure of the origin server information api.OriginPeer is as follows:

          Field Type Description
          Peer string Endpoint of the origin server, such as http://2.2.2.2:9090 or https://test.baidu.com:9090. The origin server type can be in the forms of domain name, IP and bucket. The sample code shows an origin server type in IP form, and all origin servers of a domain name shall be in the same type. If you use default port, meaning HTTP 80 and HTTPS 443, the origin server is regarded to support the two protocols of HTTP and HTTPS by CDN system.
          Host string It indicates the Host that is carried in HTTP request header when forwarding to the origin; if not set, use DefaultHost
          Backup bool It indicates whether it is a standby origin server. The standby origin server is used when the primary origin server is not available. False means the origin server is the primary origin server. It should be noted that the default value of the bool object in golang is false, and if the Backup value is not explicitly set, it is false by default.
          Follow302 bool true means when the origin server returns 302 when the request is forwarded to origin, the CDN system processes Location redirection, actively gets resources and return it to the client. False means when the origin server returns 302, the CDN system passes through 302 to the client. It should be noticed that the current Follow302 has already been modified as all the origin server-level configuration, so all the origin server Follow302 should be the same, or unpredictable results may occur.

          Enable/Stop/Delete the Accelerated Domain Name

          cli := client.GetDefaultClient()      
          testDomain := "test_go_sdk.baidu.com" 
                                                
          //Enable the acceleration domain name                             
          err := cli.EnableDomain(testDomain)   
          fmt.Printf("err:%+v\n", err)          
                                                
          //Deactivate the acceleration domain name                             
          err = cli.DisableDomain(testDomain)   
          fmt.Printf("err:%+v\n", err)  
          
          //Delete the accelerated domain names under the username 
          err = cli.DeleteDomain(testDomain) 
          fmt.Printf("err:%+v\n", err) 
          Previous
          CdnClient
          Next
          Domain Name Configuration Interface