本文整理匯總了Golang中github.com/aws/aws-sdk-go/private/protocol/restjson.Unmarshal函數的典型用法代碼示例。如果您正苦於以下問題:Golang Unmarshal函數的具體用法?Golang Unmarshal怎麽用?Golang Unmarshal使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Unmarshal函數的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestOutputService1ProtocolTestScalarMembersCase1
func TestOutputService1ProtocolTestScalarMembersCase1(t *testing.T) {
sess := session.New()
svc := NewOutputService1ProtocolTest(sess, &aws.Config{Endpoint: aws.String("https://test")})
buf := bytes.NewReader([]byte("{\"Str\": \"myname\", \"Num\": 123, \"FalseBool\": false, \"TrueBool\": true, \"Float\": 1.2, \"Double\": 1.3, \"Long\": 200, \"Char\": \"a\"}"))
req, out := svc.OutputService1TestCaseOperation1Request(nil)
req.HTTPResponse = &http.Response{StatusCode: 200, Body: ioutil.NopCloser(buf), Header: http.Header{}}
// set headers
req.HTTPResponse.Header.Set("ImaHeader", "test")
req.HTTPResponse.Header.Set("X-Foo", "abc")
// unmarshal response
restjson.UnmarshalMeta(req)
restjson.Unmarshal(req)
assert.NoError(t, req.Error)
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "a", *out.Char)
assert.Equal(t, 1.3, *out.Double)
assert.Equal(t, false, *out.FalseBool)
assert.Equal(t, 1.2, *out.Float)
assert.Equal(t, "test", *out.ImaHeader)
assert.Equal(t, "abc", *out.ImaHeaderLocation)
assert.Equal(t, int64(200), *out.Long)
assert.Equal(t, int64(123), *out.Num)
assert.Equal(t, int64(200), *out.Status)
assert.Equal(t, "myname", *out.Str)
assert.Equal(t, true, *out.TrueBool)
}
示例2: TestOutputService9ProtocolTestSupportsHeaderMapsCase1
func TestOutputService9ProtocolTestSupportsHeaderMapsCase1(t *testing.T) {
sess := session.New()
svc := NewOutputService9ProtocolTest(sess, &aws.Config{Endpoint: aws.String("https://test")})
buf := bytes.NewReader([]byte("{}"))
req, out := svc.OutputService9TestCaseOperation1Request(nil)
req.HTTPResponse = &http.Response{StatusCode: 200, Body: ioutil.NopCloser(buf), Header: http.Header{}}
// set headers
req.HTTPResponse.Header.Set("Content-Length", "10")
req.HTTPResponse.Header.Set("X-Bam", "boo")
req.HTTPResponse.Header.Set("X-Foo", "bar")
// unmarshal response
restjson.UnmarshalMeta(req)
restjson.Unmarshal(req)
assert.NoError(t, req.Error)
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "10", *out.AllHeaders["Content-Length"])
assert.Equal(t, "boo", *out.AllHeaders["X-Bam"])
assert.Equal(t, "bar", *out.AllHeaders["X-Foo"])
assert.Equal(t, "boo", *out.PrefixedHeaders["Bam"])
assert.Equal(t, "bar", *out.PrefixedHeaders["Foo"])
}
示例3: TestOutputService8ProtocolTestIgnoresExtraDataCase1
func TestOutputService8ProtocolTestIgnoresExtraDataCase1(t *testing.T) {
svc := NewOutputService8ProtocolTest(nil)
buf := bytes.NewReader([]byte("{\"foo\": \"bar\"}"))
req, out := svc.OutputService8TestCaseOperation1Request(nil)
req.HTTPResponse = &http.Response{StatusCode: 200, Body: ioutil.NopCloser(buf), Header: http.Header{}}
// set headers
// unmarshal response
restjson.UnmarshalMeta(req)
restjson.Unmarshal(req)
assert.NoError(t, req.Error)
// assert response
assert.NotNil(t, out) // ensure out variable is used
}
示例4: TestOutputService11ProtocolTestStreamingPayloadCase1
func TestOutputService11ProtocolTestStreamingPayloadCase1(t *testing.T) {
svc := NewOutputService11ProtocolTest(nil)
buf := bytes.NewReader([]byte("abc"))
req, out := svc.OutputService11TestCaseOperation1Request(nil)
req.HTTPResponse = &http.Response{StatusCode: 200, Body: ioutil.NopCloser(buf), Header: http.Header{}}
// set headers
// unmarshal response
restjson.UnmarshalMeta(req)
restjson.Unmarshal(req)
assert.NoError(t, req.Error)
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "abc", string(out.Stream))
}
示例5: TestOutputService3ProtocolTestTimestampMembersCase1
func TestOutputService3ProtocolTestTimestampMembersCase1(t *testing.T) {
svc := NewOutputService3ProtocolTest(nil)
buf := bytes.NewReader([]byte("{\"TimeMember\": 1398796238, \"StructMember\": {\"foo\": 1398796238}}"))
req, out := svc.OutputService3TestCaseOperation1Request(nil)
req.HTTPResponse = &http.Response{StatusCode: 200, Body: ioutil.NopCloser(buf), Header: http.Header{}}
// set headers
// unmarshal response
restjson.UnmarshalMeta(req)
restjson.Unmarshal(req)
assert.NoError(t, req.Error)
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, time.Unix(1.398796238e+09, 0).UTC().String(), out.StructMember.Foo.String())
assert.Equal(t, time.Unix(1.398796238e+09, 0).UTC().String(), out.TimeMember.String())
}
示例6: TestOutputService2ProtocolTestBlobMembersCase1
func TestOutputService2ProtocolTestBlobMembersCase1(t *testing.T) {
svc := NewOutputService2ProtocolTest(nil)
buf := bytes.NewReader([]byte("{\"BlobMember\": \"aGkh\", \"StructMember\": {\"foo\": \"dGhlcmUh\"}}"))
req, out := svc.OutputService2TestCaseOperation1Request(nil)
req.HTTPResponse = &http.Response{StatusCode: 200, Body: ioutil.NopCloser(buf), Header: http.Header{}}
// set headers
// unmarshal response
restjson.UnmarshalMeta(req)
restjson.Unmarshal(req)
assert.NoError(t, req.Error)
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "hi!", string(out.BlobMember))
assert.Equal(t, "there!", string(out.StructMember.Foo))
}
示例7: TestOutputService5ProtocolTestListsWithStructureMemberCase1
func TestOutputService5ProtocolTestListsWithStructureMemberCase1(t *testing.T) {
svc := NewOutputService5ProtocolTest(nil)
buf := bytes.NewReader([]byte("{\"ListMember\": [{\"Foo\": \"a\"}, {\"Foo\": \"b\"}]}"))
req, out := svc.OutputService5TestCaseOperation1Request(nil)
req.HTTPResponse = &http.Response{StatusCode: 200, Body: ioutil.NopCloser(buf), Header: http.Header{}}
// set headers
// unmarshal response
restjson.UnmarshalMeta(req)
restjson.Unmarshal(req)
assert.NoError(t, req.Error)
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "a", *out.ListMember[0].Foo)
assert.Equal(t, "b", *out.ListMember[1].Foo)
}
示例8: TestOutputService7ProtocolTestComplexMapValuesCase1
func TestOutputService7ProtocolTestComplexMapValuesCase1(t *testing.T) {
sess := session.New()
svc := NewOutputService7ProtocolTest(sess, &aws.Config{Endpoint: aws.String("https://test")})
buf := bytes.NewReader([]byte("{\"MapMember\": {\"a\": 1398796238, \"b\": 1398796238}}"))
req, out := svc.OutputService7TestCaseOperation1Request(nil)
req.HTTPResponse = &http.Response{StatusCode: 200, Body: ioutil.NopCloser(buf), Header: http.Header{}}
// set headers
// unmarshal response
restjson.UnmarshalMeta(req)
restjson.Unmarshal(req)
assert.NoError(t, req.Error)
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, time.Unix(1.398796238e+09, 0).UTC().String(), out.MapMember["a"].String())
assert.Equal(t, time.Unix(1.398796238e+09, 0).UTC().String(), out.MapMember["b"].String())
}
示例9: TestOutputService4ProtocolTestListsCase1
func TestOutputService4ProtocolTestListsCase1(t *testing.T) {
sess := session.New()
svc := NewOutputService4ProtocolTest(sess, &aws.Config{Endpoint: aws.String("https://test")})
buf := bytes.NewReader([]byte("{\"ListMember\": [\"a\", \"b\"]}"))
req, out := svc.OutputService4TestCaseOperation1Request(nil)
req.HTTPResponse = &http.Response{StatusCode: 200, Body: ioutil.NopCloser(buf), Header: http.Header{}}
// set headers
// unmarshal response
restjson.UnmarshalMeta(req)
restjson.Unmarshal(req)
assert.NoError(t, req.Error)
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "a", *out.ListMember[0])
assert.Equal(t, "b", *out.ListMember[1])
}
示例10: TestOutputService10ProtocolTestJSONPayloadCase1
func TestOutputService10ProtocolTestJSONPayloadCase1(t *testing.T) {
svc := NewOutputService10ProtocolTest(nil)
buf := bytes.NewReader([]byte("{\"Foo\": \"abc\"}"))
req, out := svc.OutputService10TestCaseOperation1Request(nil)
req.HTTPResponse = &http.Response{StatusCode: 200, Body: ioutil.NopCloser(buf), Header: http.Header{}}
// set headers
req.HTTPResponse.Header.Set("X-Foo", "baz")
// unmarshal response
restjson.UnmarshalMeta(req)
restjson.Unmarshal(req)
assert.NoError(t, req.Error)
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, "abc", *out.Data.Foo)
assert.Equal(t, "baz", *out.Header)
}
示例11: TestOutputService6ProtocolTestMapsCase1
func TestOutputService6ProtocolTestMapsCase1(t *testing.T) {
svc := NewOutputService6ProtocolTest(nil)
buf := bytes.NewReader([]byte("{\"MapMember\": {\"a\": [1, 2], \"b\": [3, 4]}}"))
req, out := svc.OutputService6TestCaseOperation1Request(nil)
req.HTTPResponse = &http.Response{StatusCode: 200, Body: ioutil.NopCloser(buf), Header: http.Header{}}
// set headers
// unmarshal response
restjson.UnmarshalMeta(req)
restjson.Unmarshal(req)
assert.NoError(t, req.Error)
// assert response
assert.NotNil(t, out) // ensure out variable is used
assert.Equal(t, int64(1), *out.MapMember["a"][0])
assert.Equal(t, int64(2), *out.MapMember["a"][1])
assert.Equal(t, int64(3), *out.MapMember["b"][0])
assert.Equal(t, int64(4), *out.MapMember["b"][1])
}