Domain Name Configuration Interface
Query the Accelerated Domain Name Details GetDomainConfig
Query all configuration information of a specific domain name.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
domainConfig, err := cli.GetDomainConfig(testDomain)
fmt.Printf("domainConfig:%+v\n", domainConfig)
fmt.Printf("err:%+v\n", err)
domainConfig
is an object in *api.DomainConfig
type, and its structure is relatively complex, as shown below:
Field | Type | Description |
---|---|---|
Domain | string | Domain name information, such as: test.baidu.com . |
Cname | string | Domain name CNAME, such as: test.baidu.com.a.bdydns.com . |
Status | string | State of domain name, with the legal values ‘RUNNING’, ‘STOPPED’ and ‘OPERATING’. |
CreateTime | string | Time to create the domain name, UTC time, such as: 2019-09-02T10:08:38Z . |
LastModifyTime | string | Latest time to modify the domain name configuration, UTC time, such as: 2019-09-06T15:00:21Z . |
IsBan | string | Whether it is disabled, the disabled means arrears or that other illegal operations are blocked by the system, and the blocked domain name cannot enjoy the acceleration service. ON means unblocked, and ‘YES` means blocked. |
Origin | []api.OriginPeer | Origin server information, described in detail in the interface for creating an accelerated domain name. |
DefaultHost | string | The default member host will be explained in details when creating acceleration domain name. |
CacheTTL | []api.CacheTTL | The cache policies for file types and paths are described in detail in the section of ‘Set/Query cache expiration rules `. |
LimitRate | int | Download speed limit, with the unit of Byte/s. |
RequestAuth | api.RequestAuth | Access authentication settings are described in detail in ‘Set access authentication’. |
Https | api.HTTPSConfig | HTTPS acceleration configuration, it is described in detail in setting HTTPS acceleration. |
FollowProtocol | bool | Whether the follow origin protocol is enabled. true means the follow origin protocol is enabled, that is, when the access resource is a URL such as https://xxx or http://xxx, the origin also uses the corresponding scheme, namely HTTPS and HTTP respectively. |
SeoSwitch | api.SeoSwitch | seo switch configuration, it is described in detail in setting SEO switch property. |
Set/Query Cache Expiration Rules SetCacheTTL/GetCacheTTL
Set cache policies related to files, directories and error codes. Reasonable settings of cache policies improve the hit rate.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
//Set to use origin server rules for the cache policy
err := cli.SetCacheTTL(testDomain, []api.CacheTTL{
{
Type: "origin",
Value: "-",
TTL: 0,
},
})
fmt.Printf("err:%+v\n", err)
//Set cache policy. Set suffix rules, directory rules, path exact match and error codes respectively.
err = cli.SetCacheTTL(testDomain, []api.CacheTTL{
{
Type: "suffix",
Value: ".jpg",
TTL: 420000,
Weight: 30,
},
{
Type: "path",
Value: "/js",
TTL: 10000,
},
{
Type: "exactPath",
Value: "index.html",
TTL: 600,
Weight: 100,
},
{
Type: "code",
Value: "404",
TTL: 600,
Weight: 100,
},
})
fmt.Printf("err:%+v\n", err)
//Query cache policy
cacheTTls, err := cli.GetCacheTTL(testDomain)
fmt.Printf("cacheTTls:%+v\n", cacheTTls)
fmt.Printf("err:%+v\n", err)
cacheTTls
contains all cache policies, and each cache policy is represented by an object in api.CacheTTL
type. The cache policy structure is described as follows.
Field | Type | Description |
---|---|---|
Type | string | Type of cache policy The valid types include: suffix , path , origin , code and exactPath . “suffix " means the file name suffix, “path " means the directory in the url, “origin " means the origin server rule. There is only one such rule, and only the weight is required. The value is “- ", and ttl is 0. “code " means exception code cache. For example, you can configure 404 to cache 100 s. “exactPath " means the path is completely matched. |
Value | string | Configuration rules for the specified type in “type”. |
Weight | int | Weight, an integer between 0-100. The higher the weight, the higher the priority. The default is 0, and the priority is of no use when it is code type and can be ignored. The higher the weight, the higher the priority; the rule has a priority to take effect. It is not recommended to configure the same weight for two cache strategies, and if the weight is same, one of the strategies will be selected randomly to take effect. |
TTL | int | Cache duration, in seconds |
Set/Query Cached Parameter Filtration Rules SetCacheUrlArgs/GetCacheUrlArgs
Set cache key; the cache key is the key adopted when CDN system caches a certain resource, and a url may bring many parameters; so, when should all the parameters be placed in the cache key? In fact, it is not necessary. Different settings are shown below.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
//Set all URL cache
err := cli.SetCacheUrlArgs(testDomain, &api.CacheUrlArgs{
CacheFullUrl: true,
})
fmt.Printf("err:%+v\n", err)
//Set to have some parameters for cache
err = cli.SetCacheUrlArgs(testDomain, &api.CacheUrlArgs{
CacheFullUrl: false,
CacheUrlArgs: []string{"name", "id"},
})
fmt.Printf("err:%+v\n", err)
//Set to ignore all parameters
err = cli.SetCacheUrlArgs(testDomain, &api.CacheUrlArgs{
CacheFullUrl: false,
CacheUrlArgs: []string{"name", "id"},
})
fmt.Printf("err:%+v\n", err)
//Query URL parameter cache settings
cacheUrlArgs, err := cli.GetCacheUrlArgs(testDomain)
fmt.Printf("cacheUrlArgs:%+v\n", cacheUrlArgs)
cacheUrlArgs
is an object in api.CacheUrlArgs
type, and it is described in detail as follows:
Field | Type | Description |
---|---|---|
CacheFullUrl | bool | true or false, true means supporting full URL cache, and false means ignoring parameter cache (some parameters can be retained). Note that if CacheFullUrl is not explicitly assigned to true or false in golang, and then get the null value false. |
CacheUrlArgs | []string | When CacheFullUrl is true, this item does not work; when CacheFullUrl is false, this item represents the list of retained parameters. If it is empty, it means ignoring all parameters. |
Set/Query Custom Error Code Pages SetErrorPage/GetErrorPage
The user can customize the redirected page returned to the user by the CDN system when errors occur in the origin server access or internal CDN system (usually returning 4xx or 5xx error code), and the user can set the redirected page link.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
//Set the redirected page when an error appears
err := cli.SetErrorPage(testDomain, []api.ErrorPage{
{
Code: 510,
RedirectCode: 301,
Url: "/customer_404.html",
},
{
Code: 403,
//Here, RedirectCode is not set, which indicates that the default 302 is used for redirection
Url: "/custom_403.html",
},
})
fmt.Printf("err:%+v\n", err)
//Cancel to set the redirection page when an error occurs
err = cli.SetErrorPage(testDomain, []api.ErrorPage{})
fmt.Printf("err:%+v\n", err)
//Set the redirected page when an error appears
err = cli.SetErrorPage(testDomain, []api.ErrorPage{})
fmt.Printf("err:%+v\n", err)
//Query the wrong redirected page set before
errorPages, err := cli.GetErrorPage(testDomain)
fmt.Printf("errorPages:%+v\n", errorPages)
errorPages
is an object in []api.ErrorPage
type, and the api.ErrorPage
structure is described in detail as follows:
Field | Type | Description |
---|---|---|
Code | int | The specific status code must be the standard error code of HTTP, and cannot be such special status code as 408, 444 or 499 and others concerning client exception/early disconnection |
RedirectCode | int | Redirect status code, the type of redirection when an error code appears. You can select 301 or 302, and the default is 302. |
Url | string | Redirect target address . When an error code occurs, redirect to your custom url, namely, the value of Location in HTTP message in the 301 or 302 redirection, and it is an url. |
Set/Query Referer Access Control SetRefererACL/GetRefererACL
Set Referer access control rules. When it redirects to the resource through a browser or other forms, the browser usually adds Referer information to the request header. The CDN system supports to filter Referer, and you can set Referer blacklist or whitelist. Respond 403 when a request that Referer appears in the blacklist arrives, and respond 403 when the request that Referer does not appear in the whitelist arrives. You can only set either the blacklist or the whitelist. When a whitelist is set, and the filter rule is null, the whitelist does not take effect.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
isAllowEmpty := true
//Set whitelist ACL
err := cli.SetRefererACL(testDomain, nil, []string{
"a.bbbbbb.c",
"*.baidu.com.*",
}, isAllowEmpty)
fmt.Printf("err:%+v\n", err)
//When you set the whitelist to be empty, the whitelist rule does not take effect.
err = cli.SetRefererACL(testDomain, nil, []string{}, isAllowEmpty)
fmt.Printf("err:%+v\n", err)
//Set blacklist ACL
err = cli.SetRefererACL(testDomain, []string{
"a.b.c",
"*.xxxxx.com.*",
}, nil, isAllowEmpty)
fmt.Printf("err:%+v\n", err)
//Query referer ACL settings
refererACL, err := cli.GetRefererACL(testDomain)
fmt.Printf("refererACL:%+v\n", refererACL)
fmt.Printf("err:%+v\n", err)
isAllowEmpty
means whether to allow empty Referer access. true means allowing empty Referer access, that is, if Referer is empty, neither blacklist nor whitelist takes effect. In most cases, this value is set to true ; false means not allowing empty Referer access. When it is set to false, if there is no Referer in the HTTP message accessed, the CDN system returns 403. refererACL
is an object in api.RefererACL
type, and it is described in details as follows:
Field | Type | Description |
---|---|---|
BlackList | []string | Optional, indicating the referer blacklist. Support the wildcard ∗, and no protocol is required. For example, to set a blacklist domain name, you only set it as “www.xxx.com " instead of “http://www.xxx.com ". |
WhiteList | []string | Optional, list type, indicating the referer whitelist. Support the wildcard ∗ and no protocol is required. |
AllowEmpty | bool | Required, bool type, indicating whether to allow empty referer access. true means allowing empty referer access. |
Set/Query IP Access Control SetIpACL/GetIpACL
CDN gets the client IP, matches it with the IP blacklist/whitelist in the configuration and rejects/passes the matched client request.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
//Set IP whitelist
err := cli.SetIpACL(testDomain, []string{
"1.1.1.1",
"2.2.2.2",
}, nil)
fmt.Printf("err:%+v\n", err)
//Set IP blacklist, IP in CIDR format
err = cli.SetIpACL(testDomain, nil, []string{
"1.2.3.4/24",
})
fmt.Printf("err:%+v\n", err)
//Query IP blacklist and whitelist settings
ipACL, err := cli.GetIpACL(testDomain)
fmt.Printf("ipACL:%+v\n", ipACL)
fmt.Printf("err:%+v\n", err)
ipACL
is an object in api.IpACL
type, and the details are as follows:
Field | Type | Description |
---|---|---|
BlackList | []string | IP blacklist. When you set the blacklist to take effect, if the client IP is in the BlackList, the CDN system returns 403. You cannot set BlackList and WhiteList at the same time. |
WhiteList | []string | IP whitelist. When you set the whitelist to take effect, if the WhiteList is empty, there is no whitelist effect. When WhiteList is not empty, only the client IP belonging to WhiteList can access. Also, cannot be set simultaneously with BlackList. |
Set Access Authentication SetDomainRequestAuth
Advanced authorization is also designated to prevent contents of origin server from being theft, is more secure than Referer blacklist/whitelist and IP blacklist/whitelist.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
err := cli.SetDomainRequestAuth(testDomain, &api.RequestAuth{
Type: "c",
Key1: "secretekey1",
Key2: "secretekey2",
Timeout: 300,
WhiteList: []string{
"/crossdomain.xml",
},
SignArg: "sign",
TimeArg: "t",
})
fmt.Printf("err:%+v\n", err)
The sample code sets a Type-C authentication method, and the corresponding field is in Advanced Authentication. Instructions for extraordinary information.
Set Domain Name Rate Limit SetLimitRate
Limit the maximum response speed rate of every request transmitting to the client under the domain name. The rate is for a single request, and it automatically doubles for multiple requests.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
//Set the speed limit to 1024Bytes/s for a single request.
err := cli.SetLimitRate(testDomain, 1024)
fmt.Printf("err:%+v\n", err)
//No speed limitation
err = cli.SetLimitRate(testDomain, 0)
fmt.Printf("err:%+v\n", err)
Set/Query Cors Cross-domain SetCors/GetCors
Cross-domain access means that the domain in which the resource initiating the request is located is different from the domain in which the resource pointed to by the request is located. For security reasons, browsers will restrict this non-homologous access. By enabling such feature, the users can clear the cache and access the configuration cross domains, and after the object of origin server (BOS) is updated, all caches corresponding to CDN can be updated automatically and synchronously.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
//Set cross-domain domain names which are allowed.
err := cli.SetCors(testDomain, true, []string{
"http://www.baidu.com",
"http://*.bce.com",
})
fmt.Printf("err:%+v\n", err)
//Cancel cross-domain settings
err = cli.SetCors(testDomain, false, nil)
fmt.Printf("err:%+v\n", err)
//Query cross-domain settings
cors, err := cli.GetCors(testDomain)
fmt.Printf("cors:%+v\n", cors)
fmt.Printf("err:%+v\n", err)
Set/Query IP Access Limit SetAccessLimit/GetAccessLimit
For all access paths, limit the number of visits per second of a single IP.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
//Set the frequency limitation for a single IP access as 200/s
err := cli.SetAccessLimit(testDomain, &api.AccessLimit{
Enabled: true,
Limit: 200,
})
fmt.Printf("err:%+v\n", err)
//Cancel IP access frequency limit
err = cli.SetAccessLimit(testDomain, &api.AccessLimit{
Enabled: false,
Limit: 0,
})
fmt.Printf("err:%+v\n", err)
//Query IP access limit settings
accessLimit, err := cli.GetAccessLimit(testDomain)
fmt.Printf("accessLimit:%+v\n", accessLimit)
fmt.Printf("err:%+v\n", err)
accessLimit
is an object in api.AccessLimit
type, and the details are as follows:
Field | Type | Description |
---|---|---|
Enabled | bool | true means enabling visit frequency limit for a single IP node, and false means cancelling frequency limit. Here, please note that the bool object of golang has a zero value, which is false, so to set the limit value, Enable must be set as true. |
Limit | int | Maximum number of requests of a single IP node in one second. When enabled is true, this item is 1000 by default, and when enabled is false, this item is meaningless. |
Set/Query and Get Real User IP SetClientIp/GetClientIp
When using CDN acceleration, the user can also get the real IP address or client IP address of the access source.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
//Set Client IP. The origin server can get the client IP address of the access source, carrying True-Client-Ip;
err := cli.SetClientIp(testDomain, &api.ClientIp{
Enabled: true,
Name: "True-Client-IP",
})
fmt.Printf("err:%+v\n", err)
//Set Real IP: The origin server can access the real IP address of access source, carrying X-Real-IP.
err = cli.SetClientIp(testDomain, &api.ClientIp{
Enabled: true,
Name: "X-Real-IP",
})
fmt.Printf("err:%+v\n", err)
//Disable the setting of Client IP and Real IP
err = cli.SetClientIp(testDomain, &api.ClientIp{
Enabled: false,
})
fmt.Printf("err:%+v\n", err)
//Query settings about the client IP
clientIp, err := cli.GetClientIp(testDomain)
fmt.Printf("err:%+v\n", err)
fmt.Printf("clientIp:%+v\n", clientIp)
clientIp
is an object in api.ClientIp
type, and the details are as follows:
Field | Type | Description |
---|---|---|
Enabled | bool | true means enabled, and false means disabled. |
Name | string | You can set it as either “True-Client-Ip " or “X-Real-IP ", and the default is “True-Client-Ip ". When enabled is false, this item is meaningless. |
Update the Forward-to-origin Address of the Acceleration Domain Name SetDomainOrigin
The origin address of the accelerated domain name can be set when the domain name is created, or it can be updated after created.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
err := cli.SetDomainOrigin(testDomain, []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,
},
}, "www.baidu.com")
fmt.Printf("err:%+v\n", err)
The api.OriginPeer
type is described in detail in the section of Create an accelerated domain name.
Set Protocol to Follow Forward-to-origin SetFollowProtocol
Setting protocol follow origin means that origin protocol of the CDN node is consistent with the access protocol of the client.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
//Set protocol to follow forward-to-origin
err := cli.SetFollowProtocol(testDomain, true)
fmt.Printf("err:%+v\n", err)
//Cancel to set protocol follow origin
err = cli.SetFollowProtocol(testDomain, false)
fmt.Printf("err:%+v\n", err)
Set/Query Range Origin SetRangeSwitch/GetRangeSwitch
Set Range origin, which helps reduce the origin consumption of large file delivery and shortens the response time. This feature requires the origin server to support Range request.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
//Set Range origin
err := cli.SetRangeSwitch(testDomain, true)
fmt.Printf("err:%+v\n", err)
//Cancel setting range forward-to-origin
err = cli.SetRangeSwitch(testDomain, false)
fmt.Printf("err:%+v\n", err)
//Query range origin settings
rangeSwitch, err := cli.GetRangeSwitch(testDomain)
fmt.Printf("rangeSwitch:%+v\n", rangeSwitch)
Set/Query Mobile Access Control SetMobileAccess/GetMobileAccess
By enabling the mobile access control, the origin server can distribute the resource contents on the mobile end/PC end in a targeted manner. Currently, custom configuration on mobile end is not supported temporarily.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
//Set up mobile access
err := cli.SetMobileAccess(testDomain, true)
fmt.Printf("err:%+v\n", err)
//Cancel to set mobile access
err = cli.SetMobileAccess(testDomain, false)
fmt.Printf("err:%+v\n", err)
//Query mobile access settings
mobileAccess, err := cli.GetMobileAccess(testDomain)
fmt.Printf("mobileAccess:%+v\n", mobileAccess)
fmt.Printf("err:%+v\n", err)
Set/Query HttpHeader SetHttpHeader/GetHttpHeader
CDN supports to modify the header information in the response (HTTP response header) from the CDN node to the client and the request (HTTP request header) from the CDN node to the origin server.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
//Set the HTTP request header added or deleted when the CDN system works
err := cli.SetHttpHeader(testDomain, []api.HttpHeader{
{
Type: "origin",
Header: "x-auth-cn",
Value: "xxxxxxxxx",
Action: "remove",
},
{
Type: "response",
Header: "content-type",
Value: "application/octet-stream",
Action: "add",
},
})
fmt.Printf("err:%+v\n", err)
//Cancel the HTTP request header added while CDN system is working
err = cli.SetHttpHeader(testDomain, []api.HttpHeader{})
fmt.Printf("err:%+v\n", err)
//Query the HTTP request headers added or deleted when the CDN system is working
headers, err := cli.GetHttpHeader(testDomain)
fmt.Printf("headers:%+v\n", headers)
fmt.Printf("err:%+v\n", err)
headers
is an object in api.HttpHeader
type, and it is described in detail as follows:
Field | Type | Description |
---|---|---|
Type | string | "origin " means this header takes effect when it forwards to origin, and “response " means it takes effect when it responds to the user. |
Header | string | header is an http header field. Generally, it is a standard Header of HTTP, or it can be a custom one by user, such as x-bce-authoriztion. |
Value | string | Assign the Header value. |
Action | string | It indicates whether to delete or add. You can select remove/add, and the default is add; the console only supports add action at present; API performs compatibility with the back-end remove configuration. |
Describe | string | Description, optional, can be Chinese, uniformly use Unicode; the length should be no more than 100 characters |
Set/Query SEO Switch property SetDomainSeo/GetDomainSeo
SEO (Search Engine Optimization) optimization is a method to improve the website’s natural ranking in related search engines by using rules of the search engines. Currently, CDN system supports two optimal configurations: (1)Search engine enables automatic forward-to-origin;(2)The data link with Baidu search.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
//Set SEO optimization
err := cli.SetDomainSeo(testDomain, &api.SeoSwitch{
DirectlyOrigin: "ON",
PushRecord: "OFF",
})
fmt.Printf("err:%+v\n", err)
//Query SEO optimization settings
seoSwitch, err := cli.GetDomainSeo(testDomain)
fmt.Printf("seoSwitch:%+v\n", seoSwitch)
fmt.Printf("err:%+v\n", err)
seoSwitch
is an object in api.SeoSwitch
type, and the details are as follows:
Field | Type | Description |
---|---|---|
DirectlyOrigin | string | ON means setting direct forward-to-origin, and OFF means the opposite. |
PushRecord | string | ON means pushing access records to Baidu search, and OFF means the opposite. |
Set/Query Page Optimization SetFileTrim/GetFileTrim
After page optimization is enabled, it automatically deletes annotations and repeated white spaces in html, which effectively removes redundant content on the page, reduces file size and improves the efficiency of accelerated delivery.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
//Set page optimization
err := cli.SetFileTrim(testDomain, true)
fmt.Printf("err:%+v\n", err)
//Cancel page optimization
err = cli.SetFileTrim(testDomain, false)
fmt.Printf("err:%+v\n", err)
//Query the page optimization settings
fileTrim, err := cli.GetFileTrim(testDomai
fmt.Printf("fileTrim:%+v\n", fileTrim)
fmt.Printf("err:%+v\n", err)
Set/Query Video Drag SetMediaDrag/GetMediaDrag
CDN supports to drag videos in flv and mp4 type. Enabling drag reduces the origin rate and increases the speed.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
//Set video drag
err := cli.SetMediaDrag(testDomain, &api.MediaDragConf{
Mp4: &api.MediaCfg{
DragMode: "second",
FileSuffix: []string{
"mp4",
"m4a",
"m4z",
},
StartArgName: "startIndex",
},
Flv: &api.MediaCfg{
DragMode: "byteAV",
FileSuffix: []string{},
},
})
fmt.Printf("err:%+v\n", err)
//Query video drag settings
mediaDragConf, err := cli.GetMediaDrag(testDomain)
fmt.Printf("mediaDragConf:%+v\n", mediaDragConf)
fmt.Printf("err:%+v\n", err)
mediaDragConf
is an object in api.MediaDragConf
type, and it is defined as follows:
type MediaDragConf struct {
Mp4 *MediaCfg
Flv *MediaCfg
}
You can set up the drag-and-drop related to Mp4 or Flv types of video stream, with the detailed MediaCfg
shown as follows:
Field | Type | Description |
---|---|---|
FileSuffix | []string | The CDN system supports pseudo-streaming playback of MP4 files files. Usually these files have extensions of .mp4, .m4v, and .m4a, so this fileSuffix value is a collection of file extensions, such as: [ "mp4", "m4v ", "m4a "], when type is mp4. fileSuffix is [ "mp4 "] by default; when type is flv, fileSuffix is [ "flv "] by default. |
StartArgName | string | Name of the start parameter, and the default is “start ". You can customize the parameter name, but it cannot be the same as endArgName . |
EndArgName | string | Name of the end parameter, and the default is “end ". You can customize the parameter name, but it cannot be the same as startArgName . |
DragMode | string | Drag in seconds for the mp4 type and in bytes for the flv type. For the flv type, you can select the “byteAV " or “byte” mode; for the mp4 type, you can only select the “second” mode |
Set/Query Page Compression SetContentEncoding/GetContentEncoding
After enabling the page compression feature, you can compress most static files, effectively reducing the size of transmitted content by users and enhancing the delivery effect. Currently, the page compression supports two modes: Brotli compression and Gzip compression.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
//Set the page compression algorithm to gzip
err := cli.SetContentEncoding(testDomain, true, "gzip")
fmt.Printf("err:%+v\n", err)
//Set the page compression algorithm to br
err = cli.SetContentEncoding(testDomain, true, "br")
fmt.Printf("err:%+v\n", err)
//Disable direction compression
err = cli.SetContentEncoding(testDomain, false, "br")
fmt.Printf("err:%+v\n", err)
//Query page compression algorithm. When page compression is disabled, contentEncoding is empty.
contentEncoding, err := cli.GetContentEncoding(testDomain)
fmt.Printf("contentEncoding:%+v\n", contentEncoding)
Set HTTPS Acceleration SetDomainHttps
To configure one acceleration domain name of HTTPS, you must upload the certificate. Please refer to Certificate Management for the details of certificate.
cli := client.GetDefaultClient()
testDomain := "test_go_sdk.baidu.com"
err := cli.SetDomainHttps(testDomain, &api.HTTPSConfig{
Enabled: false,
CertId: "ssl-xxxxxx",
Http2Enabled: true,
HttpRedirect: true,
HttpRedirectCode: 301,
})
fmt.Printf("err:%+v\n", err)
err = cli.SetDomainHttps(testDomain, &api.HTTPSConfig{
Enabled: false,
})
fmt.Printf("err:%+v\n", err)
The ‘api.HTTPSConfig’ structure is complex, and the details are as follows:
Field | Type | Description |
---|---|---|
Enabled | bool | Enable HTTPS acceleration, and the default is false. When enabled=false, the following fields are invalid. |
CertId | string | When enabled=true, this item is required, and it is the certificate ID returned by the SSL certificate service. When enabled=False, this item is invalid. |
HttpRedirect | bool | When enabled is true, redirect HTTP requests to HTTPS (the redirection status code is configured by httpRedirectCode), and the default is false. When enabled=false, this item is invalid, and httpsRedirect and it cannot be true at the same time. |
HttpRedirectCode | int | Redirection status code, you can select 301/302, and the default is 302. When enabled=false, this item is invalid; when httpRedirect=false, this item is invalid. |
HttpsRedirect | bool | When enabled is true, redirect HTTP requests to HTTPS (the redirection status code is configured by httpRedirectCode), and the default is false. When enabled=false, this item is invalid, and httpsRedirect and it cannot be true at the same time. |
HttpsRedirectCode | int | Redirection status code, you can select 301/302, and the default is 302. When enabled=false, this item is invalid; when httpsRedirect=false, this item is invalid. |
Http2Enabled | bool | Enable HTTP2 feature. When enabled=false, this item is invalid. Should notice the null value of the bool object of go is false. |
HttpOrigin | bool | When it is true, use the HTTP protocol to forward to origin, and the default is false. When enabled=false, this item is invalid. |
SslVersion | string | Set TLS version, it defaults to support the versions from TLSv1.0 to TLSv1.3, or set to be one of the following four version, namely SSLV3, TLSV1, TLSV11 and TLSV12; when enabled=false, it is invalid. It usually takes the default value, without setting |