当前位置: 首页>>代码示例>>Golang>>正文


Golang SignOption.AddHeaders方法代码示例

本文整理汇总了Golang中github.com/guoyao/baidubce-sdk-go/bce.SignOption.AddHeaders方法的典型用法代码示例。如果您正苦于以下问题:Golang SignOption.AddHeaders方法的具体用法?Golang SignOption.AddHeaders怎么用?Golang SignOption.AddHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/guoyao/baidubce-sdk-go/bce.SignOption的用法示例。


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

示例1: UploadPart

func (c *Client) UploadPart(uploadPartRequest UploadPartRequest,
	option *bce.SignOption) (UploadPartResponse, error) {

	bucketName := uploadPartRequest.BucketName
	objectKey := uploadPartRequest.ObjectKey
	checkBucketName(bucketName)
	checkObjectKey(objectKey)

	if uploadPartRequest.PartNumber < MIN_PART_NUMBER || uploadPartRequest.PartNumber > MAX_PART_NUMBER {
		panic(fmt.Sprintf("Invalid partNumber %d. The valid range is from %d to %d.",
			uploadPartRequest.PartNumber, MIN_PART_NUMBER, MAX_PART_NUMBER))
	}

	if uploadPartRequest.PartSize > 1024*1024*1024*5 {
		panic(fmt.Sprintf("PartNumber %d: Part Size should not be more than 5GB.", uploadPartRequest.PartSize))
	}

	params := map[string]string{
		"partNumber": strconv.Itoa(uploadPartRequest.PartNumber),
		"uploadId":   uploadPartRequest.UploadId,
	}

	req, err := bce.NewRequest("PUT", c.GetURL(bucketName, objectKey, params), uploadPartRequest.PartData)

	if err != nil {
		return nil, err
	}

	option = bce.CheckSignOption(option)
	option.AddHeaders(map[string]string{
		"Content-Length": strconv.FormatInt(uploadPartRequest.PartSize, 10),
		"Content-Type":   "application/octet-stream",
	})

	if _, ok := option.Headers["Content-MD5"]; !ok {
		option.AddHeader("Content-MD5", util.GetMD5(uploadPartRequest.PartData, true))
	}

	resp, err := c.SendRequest(req, option)

	if err != nil {
		return nil, err
	}

	uploadPartResponse := NewUploadPartResponse(resp.Header)

	return uploadPartResponse, nil
}
开发者ID:guoyao,项目名称:baidubce-sdk-go,代码行数:48,代码来源:client.go

示例2: setBucketAclFromString

func (c *Client) setBucketAclFromString(bucketName, acl string, option *bce.SignOption) error {
	params := map[string]string{"acl": ""}
	req, err := bce.NewRequest("PUT", c.GetURL(bucketName, "", params), nil)

	if err != nil {
		return err
	}

	option = bce.CheckSignOption(option)

	headers := map[string]string{"x-bce-acl": acl}
	option.AddHeaders(headers)

	_, err = c.SendRequest(req, option)

	return err
}
开发者ID:guoyao,项目名称:baidubce-sdk-go,代码行数:17,代码来源:client.go

示例3: mergeToSignOption

func (copyObjectRequest CopyObjectRequest) mergeToSignOption(option *bce.SignOption) {
	m, err := util.ToMap(copyObjectRequest)

	if err != nil {
		return
	}

	headerMap := make(map[string]string)

	for key, value := range m {
		if str, ok := value.(string); ok {
			headerMap[key] = str
		}
	}

	option.AddHeaders(headerMap)

	if copyObjectRequest.ObjectMetadata != nil {
		option.AddHeader("x-bce-metadata-directive", "replace")
		copyObjectRequest.ObjectMetadata.mergeToSignOption(option)
	} else {
		option.AddHeader("x-bce-metadata-directive", "copy")
	}
}
开发者ID:guoyao,项目名称:baidubce-sdk-go,代码行数:24,代码来源:bucket.go


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