53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package sdk
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func Test_Sign(t *testing.T) {
|
|
p :=
|
|
NewParams().RegionId("region1").
|
|
AccessKeyId("sccdsfnioasn8s7dcbsjkdc").
|
|
SignatureMethod("HMAC-SHA256").
|
|
SignatureVersion("1.0").
|
|
Nonce("asc8-asd32-23sdfcsdc-sdc").
|
|
Timestamp(time.Now().Format("2006-01-02T15:04:05Z")).
|
|
Timezone("").
|
|
ApiVersion("1.0").
|
|
SecurityToken("").
|
|
Locale("").
|
|
ContentType("application/json").
|
|
Host("api.cecloudcs.com").
|
|
RequestMethod("GET").
|
|
Uri("/om/opsdemo/instance").
|
|
RequestBody("").
|
|
SecretKey("123abc").
|
|
// 扩展参数
|
|
PutQueryParams(map[string]string{
|
|
"size": "10",
|
|
})
|
|
headers := RequestHeaders(p)
|
|
sign := GenSignature(p)
|
|
fmt.Println(sign == headers[signatureHeader])
|
|
}
|
|
|
|
func Test_string(t *testing.T) {
|
|
body := "a b asdfaslkdfj" +
|
|
"sdfa dsf"
|
|
|
|
fmt.Println(body)
|
|
// 去除空格
|
|
body = strings.Replace(body, " ", "", -1)
|
|
// 去除换行符
|
|
body = strings.Replace(body, "\n", "", -1)
|
|
// 去除制表符
|
|
body = strings.Replace(body, "\t", "", -1)
|
|
// 去除回车符
|
|
body = strings.Replace(body, "\r", "", -1)
|
|
|
|
fmt.Println(body)
|
|
}
|