コード例 #1
0
ファイル: parameters.go プロジェクト: svvu/gomws
// Normalize convert all the values to string, if a value can't not
// convert to string, an error will be returned.
// Float will round to 2 decimal precision.
func (params Parameters) Normalize() (mwsHttps.Values, error) {
	nParams := mwsHttps.NewValues()
	var stringVal string
	for key, val := range params {
		switch t := val.(type) {
		default:
			err := fmt.Errorf("Unexpected type %T", t)
			return nParams, err
		case bool:
			stringVal = strconv.FormatBool(val.(bool))
		case int:
			stringVal = strconv.Itoa(val.(int))
		case float32:
			stringVal = strconv.FormatFloat(float64(val.(float32)), 'f', 2, 32)
		case float64:
			stringVal = strconv.FormatFloat(val.(float64), 'f', 2, 64)
		case string:
			stringVal = val.(string)
		case time.Time:
			isoT := val.(time.Time)
			stringVal = isoT.UTC().Format(time.RFC3339) // "2006-01-02T15:04:05Z07:00"
		}
		nParams.Set(key, stringVal)
	}
	return nParams, nil
}
コード例 #2
0
ファイル: parameters_test.go プロジェクト: svvu/gomws
func TestValuesEncode(t *testing.T) {
	values := mwsHttps.NewValues()
	values.Add("key1", "a b c")

	Convey("Space should be replaced by %20", t, func() {
		encodeValue := values.Encode()
		So(encodeValue, ShouldEqual, "key1=a%20b%20c")
	})
}
コード例 #3
0
ファイル: base_test.go プロジェクト: svvu/gomws
func TestHttpClient(t *testing.T) {
	client, _ := NewMwsBase(testConfig, "V1", "Test")
	params := mwsHttps.NewValues()
	httpClient := client.HTTPClient(params)

	Convey("Http client has expected host", t, func() {
		So(httpClient.Host, ShouldEqual, "mws.amazonservices.com")
	})

	Convey("Http client has expected path", t, func() {
		So(httpClient.Path, ShouldEqual, "/Test/V1")
	})
}