• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang aws.Request类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/datacratic/aws-sdk-go/aws.Request的典型用法代码示例。如果您正苦于以下问题:Golang Request类的具体用法?Golang Request怎么用?Golang Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Request类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: UnmarshalError

func UnmarshalError(req *aws.Request) {
	bodyBytes, err := ioutil.ReadAll(req.HTTPResponse.Body)
	if err != nil {
		req.Error = err
		return
	}
	if len(bodyBytes) == 0 {
		req.Error = aws.APIError{
			StatusCode: req.HTTPResponse.StatusCode,
			Message:    req.HTTPResponse.Status,
		}
		return
	}
	var jsonErr jsonErrorResponse
	if err := json.Unmarshal(bodyBytes, &jsonErr); err != nil {
		req.Error = err
		return
	}

	codes := strings.SplitN(jsonErr.Code, "#", 2)
	req.Error = aws.APIError{
		StatusCode: req.HTTPResponse.StatusCode,
		Code:       codes[len(codes)-1],
		Message:    jsonErr.Message,
	}
}
开发者ID:datacratic,项目名称:aws-sdk-go,代码行数:26,代码来源:jsonrpc.go


示例2: UnmarshalError

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 = err
		return
	}
	if len(bodyBytes) == 0 {
		r.Error = aws.APIError{
			StatusCode: r.HTTPResponse.StatusCode,
			Message:    r.HTTPResponse.Status,
		}
		return
	}
	var jsonErr jsonErrorResponse
	if err := json.Unmarshal(bodyBytes, &jsonErr); err != nil {
		r.Error = err
		return
	}

	codes := strings.SplitN(code, ":", 2)
	r.Error = aws.APIError{
		StatusCode: r.HTTPResponse.StatusCode,
		Code:       codes[0],
		Message:    jsonErr.Message,
	}
}
开发者ID:datacratic,项目名称:aws-sdk-go,代码行数:27,代码来源:restjson.go


示例3: Build

func Build(req *aws.Request) {
	var buf []byte
	var err error
	if req.ParamsFilled() {
		buf, err = jsonutil.BuildJSON(req.Params)
		if err != nil {
			req.Error = err
			return
		}
	} else {
		buf = emptyJSON
	}

	if req.Service.TargetPrefix != "" || string(buf) != "{}" {
		req.SetBufferBody(buf)
	}

	if req.Service.TargetPrefix != "" {
		target := req.Service.TargetPrefix + "." + req.Operation.Name
		req.HTTPRequest.Header.Add("X-Amz-Target", target)
	}
	if req.Service.JSONVersion != "" {
		jsonVersion := req.Service.JSONVersion
		req.HTTPRequest.Header.Add("Content-Type", "application/x-amz-json-"+jsonVersion)
	}
}
开发者ID:datacratic,项目名称:aws-sdk-go,代码行数:26,代码来源:jsonrpc.go


示例4: unmarshalError

func unmarshalError(r *aws.Request) {
	defer r.HTTPResponse.Body.Close()

	if r.HTTPResponse.ContentLength == int64(0) {
		// No body, use status code to generate an APIError
		r.Error = aws.APIError{
			StatusCode: r.HTTPResponse.StatusCode,
			Code:       strings.Replace(r.HTTPResponse.Status, " ", "", -1),
			Message:    r.HTTPResponse.Status,
		}
		return
	}

	resp := &xmlErrorResponse{}
	err := xml.NewDecoder(r.HTTPResponse.Body).Decode(resp)
	if err != nil && err != io.EOF {
		r.Error = err
	} else {
		r.Error = aws.APIError{
			StatusCode: r.HTTPResponse.StatusCode,
			Code:       resp.Code,
			Message:    resp.Message,
		}
	}
}
开发者ID:datacratic,项目名称:aws-sdk-go,代码行数:25,代码来源:unmarshal_error.go


示例5: Unmarshal

func Unmarshal(r *aws.Request) {
	if r.DataFilled() {
		v := reflect.Indirect(reflect.ValueOf(r.Data))
		unmarshalBody(r, v)
		unmarshalLocationElements(r, v)
	}
}
开发者ID:datacratic,项目名称:aws-sdk-go,代码行数:7,代码来源:unmarshal.go


示例6: Build

func Build(r *aws.Request) {
	if r.ParamsFilled() {
		v := reflect.ValueOf(r.Params).Elem()
		buildLocationElements(r, v)
		buildBody(r, v)
	}
}
开发者ID:datacratic,项目名称:aws-sdk-go,代码行数:7,代码来源:build.go


示例7: setChecksumError

func setChecksumError(r *aws.Request, format string, args ...interface{}) {
	r.Retryable = true
	r.Error = &aws.APIError{
		StatusCode: r.HTTPResponse.StatusCode,
		Code:       "InvalidChecksum",
		Message:    fmt.Sprintf(format, args...),
	}
}
开发者ID:datacratic,项目名称:aws-sdk-go,代码行数:8,代码来源:checksums.go


示例8: Unmarshal

func Unmarshal(req *aws.Request) {
	if req.DataFilled() {
		err := jsonutil.UnmarshalJSON(req.Data, req.HTTPResponse.Body)
		if err != nil {
			req.Error = err
		}
	}
	return
}
开发者ID:datacratic,项目名称:aws-sdk-go,代码行数:9,代码来源:jsonrpc.go


示例9: 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:datacratic,项目名称:aws-sdk-go,代码行数:9,代码来源:customizations_test.go


示例10: addAccountID

func addAccountID(r *aws.Request) {
	if !r.ParamsFilled() {
		return
	}

	v := reflect.Indirect(reflect.ValueOf(r.Params))
	if f := v.FieldByName("AccountID"); f.Elem().String() == "" {
		f.Set(reflect.ValueOf(&defaultAccountID))
	}
}
开发者ID:datacratic,项目名称:aws-sdk-go,代码行数:10,代码来源:customizations.go


示例11: 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:datacratic,项目名称:aws-sdk-go,代码行数:10,代码来源:checksums.go


示例12: 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:datacratic,项目名称:aws-sdk-go,代码行数:12,代码来源:bucket_location.go


示例13: Build

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 = err
			return
		}
		r.SetBufferBody(buf.Bytes())
	}
}
开发者ID:datacratic,项目名称:aws-sdk-go,代码行数:13,代码来源:restxml.go


示例14: 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:datacratic,项目名称:aws-sdk-go,代码行数:15,代码来源:checksums.go


示例15: UnmarshalError

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 = err
	} else {
		r.Error = aws.APIError{
			StatusCode: r.HTTPResponse.StatusCode,
			Code:       resp.Code,
			Message:    resp.Message,
		}
	}
}
开发者ID:datacratic,项目名称:aws-sdk-go,代码行数:15,代码来源:unmarshal_error.go


示例16: 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 = err
			return
		}

		match := reBucketLocation.FindSubmatch(b)
		if len(match) > 1 {
			loc := string(match[1])
			out.LocationConstraint = &loc
		}
	}
}
开发者ID:datacratic,项目名称:aws-sdk-go,代码行数:16,代码来源:bucket_location.go


示例17: Sign

// Sign requests with signature version 4.
func Sign(req *aws.Request) {
	creds, err := req.Service.Config.Credentials.Credentials()
	if err != nil {
		req.Error = err
		return
	}

	region := req.Service.SigningRegion
	if region == "" {
		region = req.Service.Config.Region
	}

	s := signer{
		Request:         req.HTTPRequest,
		Time:            req.Time,
		ExpireTime:      req.ExpireTime,
		Query:           req.HTTPRequest.URL.Query(),
		Body:            req.Body,
		ServiceName:     req.Service.ServiceName,
		Region:          region,
		AccessKeyID:     creds.AccessKeyID,
		SecretAccessKey: creds.SecretAccessKey,
		SessionToken:    creds.SessionToken,
		Debug:           req.Service.Config.LogLevel,
		Logger:          req.Service.Config.Logger,
	}
	s.sign()
	return
}
开发者ID:datacratic,项目名称:aws-sdk-go,代码行数:30,代码来源:v4.go


示例18: buildHeader

func buildHeader(r *aws.Request, v reflect.Value, name string) {
	str, err := convertType(v)
	if err != nil {
		r.Error = err
	} else if str != nil {
		r.HTTPRequest.Header.Add(name, *str)
	}
}
开发者ID:datacratic,项目名称:aws-sdk-go,代码行数:8,代码来源:build.go


示例19: 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:datacratic,项目名称:aws-sdk-go,代码行数:8,代码来源:sse.go


示例20: buildQueryString

func buildQueryString(r *aws.Request, v reflect.Value, name string, query url.Values) {
	str, err := convertType(v)
	if err != nil {
		r.Error = err
	} else if str != nil {
		query.Set(name, *str)
	}
}
开发者ID:datacratic,项目名称:aws-sdk-go,代码行数:8,代码来源:build.go



注:本文中的github.com/datacratic/aws-sdk-go/aws.Request类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang awsutil.StringValue函数代码示例发布时间:2022-05-23
下一篇:
Golang aws.Time函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap