func SetDomainRequestAuth(cli bce.Client, domain string, requestAuth *RequestAuth) error {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"requestAuth": "",
	}
	err := httpRequest(cli, "PUT", urlPath, params, &struct {
		RequestAuth *RequestAuth `json:"requestAuth"`
	}{
		RequestAuth: requestAuth,
	}, nil)
	if err != nil {
		return err
	}
	return nil
}
SetDomainRequestAuth - set the authorized rules for requesting
For details, please refer https://cloud.baidu.com/doc/CDN/s/njxzi59g9

PARAMS:
- cli: the client agent which can perform sending request
- domain: the specified domain
- requestAuth: the rules about the auth
RETURNS:
- error: nil if success otherwise the specific error
package api
import (
	"encoding/json"
	"errors"
	"fmt"
	"strings"
	"github.com/baidubce/bce-sdk-go/bce"
)
type DomainConfig struct {
	Domain         string       `json:"domain"`
	Cname          string       `json:"cname"`
	Status         string       `json:"status"`
	CreateTime     string       `json:"createTime"`
	LastModifyTime string       `json:"lastModifyTime"`
	IsBan          string       `json:"isBan"`
	Origin         []OriginPeer `json:"origin"`
	DefaultHost    string       `json:"defaultHost,omitempty"`
	CacheTTL       []CacheTTL   `json:"cacheTTL"`
	LimitRate      int          `json:"limitRate"`
	RequestAuth    *RequestAuth `json:"requestAuth,omitempty"`
	Https          *HTTPSConfig `json:"https,omitempty"`
	FollowProtocol bool         `json:"followProtocol"`
	SeoSwitch      *SeoSwitch   `json:"seoSwitch"`
	Form           string       `json:"form"`
}
type CacheTTL struct {
	Type   string `json:"type"`
	Value  string `json:"value"`
	Weight int    `json:"weight,omitempty"`
	TTL    int    `json:"ttl"`
}
type CacheShared struct {
	Enabled    bool   `json:"enabled"`
	SharedWith string `json:"domain,omitempty"`
}
type RequestAuth struct {
	Type      string   `json:"type"`
	Key1      string   `json:"key1"`
	Key2      string   `json:"key2,omitempty"`
	Timeout   int      `json:"timeout,omitempty"`
	WhiteList []string `json:"whiteList,omitempty"`
	SignArg   string   `json:"signArg,omitempty"`
	TimeArg   string   `json:"timeArg,omitempty"`
}
type HTTPSConfig struct {
	Enabled           bool   `json:"enabled"`
	CertId            string `json:"certId,omitempty"`
	HttpRedirect      bool   `json:"httpRedirect"`
	HttpRedirectCode  int    `json:"httpRedirectCode,omitempty"`
	HttpsRedirect     bool   `json:"httpsRedirect"`
	HttpsRedirectCode int    `json:"httpsRedirectCode"`
	Http2Enabled      bool   `json:"http2Enabled"`
	SslVersion        string `json:"sslVersion,omitempty"`
	HttpOrigin bool `json:"-"`
}
type SeoSwitch struct {
	DirectlyOrigin string `json:"diretlyOrigin"`
	PushRecord     string `json:"pushRecord"`
}
type TrafficLimit struct {
	Enabled          bool   `json:"enable"`
	LimitRate        int    `json:"limitRate,omitempty"`
	LimitStartHour   int    `json:"limitStartHour,omitempty"`
	LimitEndHour     int    `json:"limitEndHour,omitempty"`
	LimitRateAfter   int    `json:"limitRateAfter,omitempty"`
	TrafficLimitArg  string `json:"trafficLimitArg,omitempty"`
	TrafficLimitUnit string `json:"trafficLimitUnit,omitempty"`
}
type HttpHeader struct {
	Type     string `json:"type"`
	Header   string `json:"header"`
	Value    string `json:"value"`
	Action   string `json:"action,omitempty"`
	Describe string `json:"describe,omitempty"`
}
type RefererACL struct {
	BlackList  []string `json:"blackList,omitempty"`
	WhiteList  []string `json:"whiteList,omitempty"`
	AllowEmpty bool     `json:"allowEmpty"`
}
type IpACL struct {
	BlackList []string `json:"blackList,omitempty"`
	WhiteList []string `json:"whiteList,omitempty"`
}
type UaACL struct {
	BlackList []string `json:"blackList,omitempty"`
	WhiteList []string `json:"whiteList,omitempty"`
}
type ErrorPage struct {
	Code         int    `json:"code"`
	RedirectCode int    `json:"redirectCode,omitempty"`
	Url          string `json:"url"`
}
type MediaCfg struct {
	FileSuffix   []string `json:"fileSuffix"`
	StartArgName string   `json:"startArgName,omitempty"`
	EndArgName   string   `json:"endArgName,omitempty"`
	DragMode     string   `json:"dragMode"`
}
type MediaDragConf struct {
	Mp4 *MediaCfg `json:"mp4,omitempty"`
	Flv *MediaCfg `json:"flv,omitempty"`
}
type ClientIp struct {
	Enabled bool   `json:"enabled"`
	Name    string `json:"name,omitempty"`
}
type RetryOrigin struct {
	Codes []int `json:"codes"`
}
type AccessLimit struct {
	Enabled bool `json:"enabled"`
	Limit   int  `json:"limit,omitempty"`
}
type CacheUrlArgs struct {
	CacheFullUrl bool     `json:"cacheFullUrl"`
	CacheUrlArgs []string `json:"cacheUrlArgs,omitempty"`
}
type CorsCfg struct {
	IsAllow bool
	Origins []string
}
func GetDomainConfig(cli bce.Client, domain string) (*DomainConfig, error) {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	config := &DomainConfig{}
	err := httpRequest(cli, "GET", urlPath, nil, nil, config)
	if err != nil {
		return nil, err
	}
	return config, nil
}
func SetDomainOrigin(cli bce.Client, domain string, origins []OriginPeer, defaultHost string) error {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"origin": "",
	}
	err := httpRequest(cli, "PUT", urlPath, params, &struct {
		Origin      []OriginPeer `json:"origin"`
		DefaultHost string       `json:"defaultHost"`
	}{
		Origin:      origins,
		DefaultHost: defaultHost,
	}, nil)
	return err
}
func SetOriginProtocol(cli bce.Client, domain string, originProtocol string) error {
	validOriginProtocols := map[string]bool{
		"http":  true,
		"https": false,
		"*":     true,
	}
	if _, ok := validOriginProtocols[originProtocol]; !ok {
		return fmt.Errorf("invalid originProtocol \"%s\", "+
			"valid value must be \"http\", \"https\" or \"*\"", originProtocol)
	}
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"originProtocol": "",
	}
	err := httpRequest(cli, "PUT", urlPath, params, map[string]interface{}{
		"originProtocol": map[string]string{
			"value": originProtocol,
		},
	}, nil)
	return err
}
func GetOriginProtocol(cli bce.Client, domain string) (string, error) {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"originProtocol": "",
	}
	respObj := &struct {
		OriginProtocol struct {
			Value string `json:"value"`
		} `json:"originProtocol"`
	}{}
	err := httpRequest(cli, "GET", urlPath, params, nil, respObj)
	if err != nil {
		return "", err
	}
	if respObj.OriginProtocol.Value == "" {
		return "http", nil
	}
	return respObj.OriginProtocol.Value, nil
}
func SetDomainSeo(cli bce.Client, domain string, seoSwitch *SeoSwitch) error {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"seoSwitch": "",
	}
	respObj := &struct {
		Status string `json:"status"`
	}{}
	err := httpRequest(cli, "PUT", urlPath, params, &struct {
		SeoSwitch *SeoSwitch `json:"seoSwitch"`
	}{
		SeoSwitch: seoSwitch,
	}, respObj)
	if err != nil {
		return err
	}
	return nil
}
func GetDomainSeo(cli bce.Client, domain string) (*SeoSwitch, error) {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"seoSwitch": "",
	}
	var respMap map[string]interface{}
	err := httpRequest(cli, "GET", urlPath, params, nil, &respMap)
	if err != nil {
		return nil, err
	}
	if _, ok := respMap["seoSwitch"]; ok {
		if _, ok := respMap["seoSwitch"].([]interface{}); !ok {
			respData, _ := json.Marshal(respMap)
			respObj := &struct {
				SeoSwitch *SeoSwitch `json:"seoSwitch"`
			}{}
			err = json.Unmarshal(respData, respObj)
			if err != nil {
				return nil, err
			}
			return respObj.SeoSwitch, nil
		}
	}
	return nil, nil
}
func GetCacheTTL(cli bce.Client, domain string) ([]CacheTTL, error) {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"cacheTTL": "",
	}
	respObj := &struct {
		CacheTTLs []CacheTTL `json:"cacheTTL"`
	}{}
	err := httpRequest(cli, "GET", urlPath, params, nil, respObj)
	if err != nil {
		return nil, err
	}
	return respObj.CacheTTLs, nil
}
func SetCacheTTL(cli bce.Client, domain string, cacheTTLs []CacheTTL) error {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"cacheTTL": "",
	}
	err := httpRequest(cli, "PUT", urlPath, params, &struct {
		CacheTTLs []CacheTTL `json:"cacheTTL"`
	}{
		CacheTTLs: cacheTTLs,
	}, nil)
	if err != nil {
		return err
	}
	return nil
}
func SetRefererACL(cli bce.Client, domain string, blackList []string, whiteList []string, isAllowEmpty bool) error {
	if len(blackList) != 0 && len(whiteList) != 0 {
		return errors.New("blackList and whiteList cannot exist at the same time")
	}
	refererACLObj := &RefererACL{
		AllowEmpty: isAllowEmpty,
	}
	if blackList != nil {
		refererACLObj.BlackList = blackList
	} else if whiteList != nil {
		refererACLObj.WhiteList = whiteList
	} else {
		return errors.New("blackList and whiteList cannot be nil at the same time")
	}
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"refererACL": "",
	}
	err := httpRequest(cli, "PUT", urlPath, params, &struct {
		RefererACL *RefererACL `json:"refererACL"`
	}{
		RefererACL: refererACLObj,
	}, nil)
	if err != nil {
		return err
	}
	return nil
}
func GetRefererACL(cli bce.Client, domain string) (*RefererACL, error) {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"refererACL": "",
	}
	refererACLObj := &RefererACL{}
	err := httpRequest(cli, "GET", urlPath, params, nil, &struct {
		RefererACL *RefererACL `json:"refererACL"`
	}{
		RefererACL: refererACLObj,
	})
	if err != nil {
		return nil, err
	}
	return refererACLObj, nil
}
func SetIpACL(cli bce.Client, domain string, blackList []string, whiteList []string) error {
	if len(blackList) != 0 && len(whiteList) != 0 {
		return errors.New("blackList and whiteList cannot exist at the same time")
	}
	ipACLObj := &IpACL{}
	if blackList != nil {
		ipACLObj.BlackList = blackList
	} else if whiteList != nil {
		ipACLObj.WhiteList = whiteList
	} else {
		return errors.New("blackList and whiteList cannot be nil at the same time")
	}
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"ipACL": "",
	}
	err := httpRequest(cli, "PUT", urlPath, params, &struct {
		IpACL *IpACL `json:"ipACL"`
	}{
		IpACL: ipACLObj,
	}, nil)
	if err != nil {
		return err
	}
	return nil
}
func GetIpACL(cli bce.Client, domain string) (*IpACL, error) {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"ipACL": "",
	}
	ipACLObj := &IpACL{}
	err := httpRequest(cli, "GET", urlPath, params, nil, &struct {
		IpACL *IpACL `json:"ipACL"`
	}{
		IpACL: ipACLObj,
	})
	if err != nil {
		return nil, err
	}
	return ipACLObj, nil
}
func SetUaACL(cli bce.Client, domain string, blackList []string, whiteList []string) error {
	if len(blackList) != 0 && len(whiteList) != 0 {
		return errors.New("blackList and whiteList cannot exist at the same time")
	}
	uaAclObj := &UaACL{}
	if blackList != nil {
		uaAclObj.BlackList = blackList
	} else if whiteList != nil {
		uaAclObj.WhiteList = whiteList
	} else {
		return errors.New("blackList and whiteList cannot be nil at the same time")
	}
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"uaAcl": "",
	}
	err := httpRequest(cli, "PUT", urlPath, params, &struct {
		UaACL *UaACL `json:"uaAcl"`
	}{
		UaACL: uaAclObj,
	}, nil)
	if err != nil {
		return err
	}
	return nil
}
func GetUaACL(cli bce.Client, domain string) (*UaACL, error) {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"uaAcl": "",
	}
	uaACLObj := &UaACL{}
	err := httpRequest(cli, "GET", urlPath, params, nil, &struct {
		UaACL *UaACL `json:"uaAcl"`
	}{
		UaACL: uaACLObj,
	})
	if err != nil {
		return nil, err
	}
	return uaACLObj, nil
}
func SetLimitRate(cli bce.Client, domain string, limitRate int) error {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"limitRate": "",
	}
	err := httpRequest(cli, "PUT", urlPath, params, &struct {
		LimitRate int `json:"limitRate"`
	}{
		LimitRate: limitRate,
	}, nil)
	if err != nil {
		return err
	}
	return nil
}
func SetTrafficLimit(cli bce.Client, domain string, trafficLimit *TrafficLimit) error {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"trafficLimit": "",
	}
	err := httpRequest(cli, "PUT", urlPath, params, &struct {
		TrafficLimit *TrafficLimit `json:"trafficLimit"`
	}{
		TrafficLimit: trafficLimit,
	}, nil)
	if err != nil {
		return err
	}
	return nil
}
func GetTrafficLimit(cli bce.Client, domain string) (*TrafficLimit, error) {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"trafficLimit": "",
	}
	respObj := &struct {
		TrafficLimit TrafficLimit `json:"trafficLimit"`
	}{}
	err := httpRequest(cli, "GET", urlPath, params, nil, respObj)
	if err != nil {
		return nil, err
	}
	return &respObj.TrafficLimit, nil
}
func SetDomainHttps(cli bce.Client, domain string, httpsConfig *HTTPSConfig) error {
	if httpsConfig.HttpRedirect && httpsConfig.HttpsRedirect {
		return errors.New("httpRedirect and httpsRedirect can not be true at the same time")
	}
	if httpsConfig.HttpRedirect {
		if httpsConfig.HttpRedirectCode != 0 && httpsConfig.HttpRedirectCode != 301 && httpsConfig.HttpRedirectCode != 302 {
			return errors.New("invalid httpRedirectCode")
		}
	}
	if httpsConfig.HttpsRedirect {
		if httpsConfig.HttpsRedirectCode != 0 && httpsConfig.HttpsRedirectCode != 301 && httpsConfig.HttpsRedirectCode != 302 {
			return errors.New("invalid httpsRedirectCode")
		}
	}
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"https": "",
	}
	err := httpRequest(cli, "PUT", urlPath, params, &struct {
		HttpsConfig *HTTPSConfig `json:"https"`
	}{
		HttpsConfig: httpsConfig,
	}, nil)
	if err != nil {
		return err
	}
	return nil
}
func GetDomainHttps(cli bce.Client, domain string) (*HTTPSConfig, error) {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"https": "",
	}
	respObj := &struct {
		HttpsConfig *HTTPSConfig `json:"https"`
	}{}
	err := httpRequest(cli, "GET", urlPath, params, nil, respObj)
	if err != nil {
		return nil, err
	}
	return respObj.HttpsConfig, nil
}
func SetOCSP(cli bce.Client, domain string, enabled bool) error {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"ocsp": "",
	}
	reqObj := map[string]interface{}{
		"ocsp": enabled,
	}
	err := httpRequest(cli, "PUT", urlPath, params, reqObj, nil)
	if err != nil {
		return err
	}
	return nil
}
func GetOCSP(cli bce.Client, domain string) (bool, error) {
	urlPath := fmt.Sprintf("/v2/domain/%s/config", domain)
	params := map[string]string{
		"ocsp": "",
	}
	respObj := &struct {
		OfflineMode bool `json:"ocsp"`
	}{}
	err := httpRequest(cli, "GET", urlPath, params, nil, respObj)
	if err != nil {
		return false, err
	}
	return respObj.OfflineMode, nil
}