本文整理汇总了Golang中github.com/convox/kernel/Godeps/_workspace/src/github.com/awslabs/aws-sdk-go/aws.Request类的典型用法代码示例。如果您正苦于以下问题:Golang Request类的具体用法?Golang Request怎么用?Golang Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: UnmarshalError
// UnmarshalError unmarshals a response error for the REST JSON protocol.
func UnmarshalError(r *aws.Request) {
code := r.HTTPResponse.Header.Get("X-Amzn-Errortype")
bodyBytes, err := ioutil.ReadAll(r.HTTPResponse.Body)
if err != nil {
r.Error = apierr.New("Unmarshal", "failed reading REST JSON error response", err)
return
}
if len(bodyBytes) == 0 {
r.Error = apierr.NewRequestError(
apierr.New("Unmarshal", r.HTTPResponse.Status, nil),
r.HTTPResponse.StatusCode,
"",
)
return
}
var jsonErr jsonErrorResponse
if err := json.Unmarshal(bodyBytes, &jsonErr); err != nil {
r.Error = apierr.New("Unmarshal", "failed decoding REST JSON error response", err)
return
}
if code == "" {
code = jsonErr.Code
}
codes := strings.SplitN(code, ":", 2)
r.Error = apierr.NewRequestError(
apierr.New(codes[0], jsonErr.Message, nil),
r.HTTPResponse.StatusCode,
"",
)
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:33,代码来源:restjson.go
示例2: Unmarshal
// Unmarshal unmarshals the REST component of a response in a REST service.
func Unmarshal(r *aws.Request) {
if r.DataFilled() {
v := reflect.Indirect(reflect.ValueOf(r.Data))
unmarshalBody(r, v)
unmarshalLocationElements(r, v)
}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:8,代码来源:unmarshal.go
示例3: Build
// Build builds the REST component of a service request.
func Build(r *aws.Request) {
if r.ParamsFilled() {
v := reflect.ValueOf(r.Params).Elem()
buildLocationElements(r, v)
buildBody(r, v)
}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:8,代码来源:build.go
示例4: assertMD5
func assertMD5(t *testing.T, req *aws.Request) {
err := req.Build()
assert.NoError(t, err)
b, _ := ioutil.ReadAll(req.HTTPRequest.Body)
out := md5.Sum(b)
assert.NotEmpty(t, b)
assert.Equal(t, base64.StdEncoding.EncodeToString(out[:]), req.HTTPRequest.Header.Get("Content-MD5"))
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:9,代码来源:customizations_test.go
示例5: verifySendMessage
func verifySendMessage(r *aws.Request) {
if r.DataFilled() && r.ParamsFilled() {
in := r.Params.(*SendMessageInput)
out := r.Data.(*SendMessageOutput)
err := checksumsMatch(in.MessageBody, out.MD5OfMessageBody)
if err != nil {
setChecksumError(r, err.Error())
}
}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:10,代码来源:checksums.go
示例6: populateLocationConstraint
func populateLocationConstraint(r *aws.Request) {
if r.ParamsFilled() && r.Config.Region != "us-east-1" {
in := r.Params.(*CreateBucketInput)
if in.CreateBucketConfiguration == nil {
r.Params = awsutil.CopyOf(r.Params)
in = r.Params.(*CreateBucketInput)
in.CreateBucketConfiguration = &CreateBucketConfiguration{
LocationConstraint: &r.Config.Region,
}
}
}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:12,代码来源:bucket_location.go
示例7: Build
// Build builds a request payload for the REST XML protocol.
func Build(r *aws.Request) {
rest.Build(r)
if t := rest.PayloadType(r.Params); t == "structure" || t == "" {
var buf bytes.Buffer
err := xmlutil.BuildXML(r.Params, xml.NewEncoder(&buf))
if err != nil {
r.Error = apierr.New("Marshal", "failed to enode rest XML request", err)
return
}
r.SetBufferBody(buf.Bytes())
}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:14,代码来源:restxml.go
示例8: UnmarshalError
// UnmarshalError unmarshals a response error for the EC2 protocol.
func UnmarshalError(r *aws.Request) {
defer r.HTTPResponse.Body.Close()
resp := &xmlErrorResponse{}
err := xml.NewDecoder(r.HTTPResponse.Body).Decode(resp)
if err != nil && err != io.EOF {
r.Error = apierr.New("Unmarshal", "failed decoding EC2 Query error response", err)
} else {
r.Error = apierr.NewRequestError(
apierr.New(resp.Code, resp.Message, nil),
r.HTTPResponse.StatusCode,
resp.RequestID,
)
}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:16,代码来源:unmarshal.go
示例9: verifyReceiveMessage
func verifyReceiveMessage(r *aws.Request) {
if r.DataFilled() && r.ParamsFilled() {
ids := []string{}
out := r.Data.(*ReceiveMessageOutput)
for _, msg := range out.Messages {
err := checksumsMatch(msg.Body, msg.MD5OfBody)
if err != nil {
ids = append(ids, *msg.MessageID)
}
}
if len(ids) > 0 {
setChecksumError(r, "invalid messages: %s", strings.Join(ids, ", "))
}
}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:15,代码来源:checksums.go
示例10: buildGetBucketLocation
func buildGetBucketLocation(r *aws.Request) {
if r.DataFilled() {
out := r.Data.(*GetBucketLocationOutput)
b, err := ioutil.ReadAll(r.HTTPResponse.Body)
if err != nil {
r.Error = apierr.New("Unmarshal", "failed reading response body", err)
return
}
match := reBucketLocation.FindSubmatch(b)
if len(match) > 1 {
loc := string(match[1])
out.LocationConstraint = &loc
}
}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:16,代码来源:bucket_location.go
示例11: validateSSERequiresSSL
func validateSSERequiresSSL(r *aws.Request) {
if r.HTTPRequest.URL.Scheme != "https" {
p := awsutil.ValuesAtPath(r.Params, "SSECustomerKey||CopySourceSSECustomerKey")
if len(p) > 0 {
r.Error = errSSERequiresSSL
}
}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:8,代码来源:sse.go
示例12: buildHeader
func buildHeader(r *aws.Request, v reflect.Value, name string) {
str, err := convertType(v)
if err != nil {
r.Error = apierr.New("Marshal", "failed to encode REST request", err)
} else if str != nil {
r.HTTPRequest.Header.Add(name, *str)
}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:8,代码来源:build.go
示例13: buildQueryString
func buildQueryString(r *aws.Request, v reflect.Value, name string, query url.Values) {
str, err := convertType(v)
if err != nil {
r.Error = apierr.New("Marshal", "failed to encode REST request", err)
} else if str != nil {
query.Set(name, *str)
}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:8,代码来源:build.go
示例14: buildHeaderMap
func buildHeaderMap(r *aws.Request, v reflect.Value, prefix string) {
for _, key := range v.MapKeys() {
str, err := convertType(v.MapIndex(key))
if err != nil {
r.Error = apierr.New("Marshal", "failed to encode REST request", err)
} else if str != nil {
r.HTTPRequest.Header.Add(prefix+key.String(), *str)
}
}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:10,代码来源:build.go
示例15: Unmarshal
// Unmarshal unmarshals a payload response for the REST XML protocol.
func Unmarshal(r *aws.Request) {
if t := rest.PayloadType(r.Data); t == "structure" || t == "" {
defer r.HTTPResponse.Body.Close()
decoder := xml.NewDecoder(r.HTTPResponse.Body)
err := xmlutil.UnmarshalXML(r.Data, decoder, "")
if err != nil {
r.Error = apierr.New("Unmarshal", "failed to decode REST XML response", err)
return
}
}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:12,代码来源:restxml.go
示例16: buildURI
func buildURI(r *aws.Request, v reflect.Value, name string) {
value, err := convertType(v)
if err != nil {
r.Error = apierr.New("Marshal", "failed to encode REST request", err)
} else if value != nil {
uri := r.HTTPRequest.URL.Path
uri = strings.Replace(uri, "{"+name+"}", EscapePath(*value, true), -1)
uri = strings.Replace(uri, "{"+name+"+}", EscapePath(*value, false), -1)
r.HTTPRequest.URL.Path = uri
}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:11,代码来源:build.go
示例17: unmarshalBody
func unmarshalBody(r *aws.Request, v reflect.Value) {
if field, ok := v.Type().FieldByName("SDKShapeTraits"); ok {
if payloadName := field.Tag.Get("payload"); payloadName != "" {
pfield, _ := v.Type().FieldByName(payloadName)
if ptag := pfield.Tag.Get("type"); ptag != "" && ptag != "structure" {
payload := v.FieldByName(payloadName)
if payload.IsValid() {
switch payload.Interface().(type) {
case []byte:
b, err := ioutil.ReadAll(r.HTTPResponse.Body)
if err != nil {
r.Error = apierr.New("Unmarshal", "failed to decode REST response", err)
} else {
payload.Set(reflect.ValueOf(b))
}
case *string:
b, err := ioutil.ReadAll(r.HTTPResponse.Body)
if err != nil {
r.Error = apierr.New("Unmarshal", "failed to decode REST response", err)
} else {
str := string(b)
payload.Set(reflect.ValueOf(&str))
}
default:
switch payload.Type().String() {
case "io.ReadSeeker":
payload.Set(reflect.ValueOf(aws.ReadSeekCloser(r.HTTPResponse.Body)))
case "aws.ReadSeekCloser", "io.ReadCloser":
payload.Set(reflect.ValueOf(r.HTTPResponse.Body))
default:
r.Error = apierr.New("Unmarshal",
"failed to decode REST response",
fmt.Errorf("unknown payload type %s", payload.Type()))
}
}
}
}
}
}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:40,代码来源:unmarshal.go
示例18: fillPresignedURL
func fillPresignedURL(r *aws.Request) {
if !r.ParamsFilled() {
return
}
params := r.Params.(*CopySnapshotInput)
// Stop if PresignedURL/DestinationRegion is set
if params.PresignedURL != nil || params.DestinationRegion != nil {
return
}
// First generate a copy of parameters
r.Params = awsutil.CopyOf(r.Params)
params = r.Params.(*CopySnapshotInput)
// Set destination region. Avoids infinite handler loop.
// Also needed to sign sub-request.
params.DestinationRegion = &r.Service.Config.Region
// Create a new client pointing at source region.
// We will use this to presign the CopySnapshot request against
// the source region
config := r.Service.Config.Copy()
config.Endpoint = ""
config.Region = *params.SourceRegion
client := New(&config)
// Presign a CopySnapshot request with modified params
req, _ := client.CopySnapshotRequest(params)
url, err := req.Presign(300 * time.Second) // 5 minutes should be enough.
if err != nil { // bubble error back up to original request
r.Error = err
}
// We have our URL, set it on params
params.PresignedURL = &url
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:40,代码来源:customizations.go
示例19: contentMD5
// contentMD5 computes and sets the HTTP Content-MD5 header for requests that
// require it.
func contentMD5(r *aws.Request) {
h := md5.New()
// hash the body. seek back to the first position after reading to reset
// the body for transmission. copy errors may be assumed to be from the
// body.
_, err := io.Copy(h, r.Body)
if err != nil {
r.Error = apierr.New("ContentMD5", "failed to read body", err)
return
}
_, err = r.Body.Seek(0, 0)
if err != nil {
r.Error = apierr.New("ContentMD5", "failed to seek body", err)
return
}
// encode the md5 checksum in base64 and set the request header.
sum := h.Sum(nil)
sum64 := make([]byte, base64.StdEncoding.EncodedLen(len(sum)))
base64.StdEncoding.Encode(sum64, sum)
r.HTTPRequest.Header.Set("Content-MD5", string(sum64))
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:25,代码来源:content_md5.go
示例20: verifySendMessageBatch
func verifySendMessageBatch(r *aws.Request) {
if r.DataFilled() && r.ParamsFilled() {
entries := map[string]*SendMessageBatchResultEntry{}
ids := []string{}
out := r.Data.(*SendMessageBatchOutput)
for _, entry := range out.Successful {
entries[*entry.ID] = entry
}
in := r.Params.(*SendMessageBatchInput)
for _, entry := range in.Entries {
if e := entries[*entry.ID]; e != nil {
err := checksumsMatch(entry.MessageBody, e.MD5OfMessageBody)
if err != nil {
ids = append(ids, *e.MessageID)
}
}
}
if len(ids) > 0 {
setChecksumError(r, "invalid messages: %s", strings.Join(ids, ", "))
}
}
}
开发者ID:nguyendangminh,项目名称:kernel,代码行数:24,代码来源:checksums.go
注:本文中的github.com/convox/kernel/Godeps/_workspace/src/github.com/awslabs/aws-sdk-go/aws.Request类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论