當前位置: 首頁>>代碼示例>>Golang>>正文


Golang bce.NewRequest函數代碼示例

本文整理匯總了Golang中github.com/guoyao/baidubce-sdk-go/bce.NewRequest函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewRequest函數的具體用法?Golang NewRequest怎麽用?Golang NewRequest使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewRequest函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: GetObjectFromRequest

func (c *Client) GetObjectFromRequest(getObjectRequest GetObjectRequest,
	option *bce.SignOption) (*Object, error) {

	checkBucketName(getObjectRequest.BucketName)
	checkObjectKey(getObjectRequest.ObjectKey)

	req, err := bce.NewRequest("GET", c.GetURL(getObjectRequest.BucketName, getObjectRequest.ObjectKey, nil), nil)

	if err != nil {
		return nil, err
	}

	option = bce.CheckSignOption(option)
	getObjectRequest.MergeToSignOption(option)

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

	if err != nil {
		return nil, err
	}

	object := &Object{
		ObjectMetadata: NewObjectMetadataFromHeader(resp.Header),
		ObjectContent:  resp.Body,
	}

	return object, nil
}
開發者ID:guoyao,項目名稱:baidubce-sdk-go,代碼行數:28,代碼來源:client.go

示例2: GetBucketAcl

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

	if err != nil {
		return nil, err
	}

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

	if err != nil {
		return nil, err
	}

	bodyContent, err := resp.GetBodyContent()

	if err != nil {
		return nil, err
	}

	var bucketAcl *BucketAcl
	err = json.Unmarshal(bodyContent, &bucketAcl)

	if err != nil {
		return nil, err
	}

	return bucketAcl, nil
}
開發者ID:guoyao,項目名稱:baidubce-sdk-go,代碼行數:29,代碼來源:client.go

示例3: GetBucketLocation

// GetBucketLocation returns the location of a bucket.
func (c *Client) GetBucketLocation(bucketName string, option *bce.SignOption) (*Location, error) {
	bucketName = c.GetBucketName(bucketName)
	params := map[string]string{"location": ""}

	req, err := bce.NewRequest("GET", c.GetURL(bucketName, "", params), nil)

	if err != nil {
		return nil, err
	}

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

	if err != nil {
		return nil, err
	}

	bodyContent, err := resp.GetBodyContent()

	if err != nil {
		return nil, err
	}

	var location *Location
	err = json.Unmarshal(bodyContent, &location)

	if err != nil {
		return nil, err
	}

	return location, nil
}
開發者ID:guoyao,項目名稱:baidubce-sdk-go,代碼行數:32,代碼來源:client.go

示例4: ListBuckets

// ListBuckets is for getting a collection of bucket.
func (c *Client) ListBuckets(option *bce.SignOption) (*BucketSummary, error) {
	req, err := bce.NewRequest("GET", c.GetURL("", "", nil), nil)

	if err != nil {
		return nil, err
	}

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

	if err != nil {
		return nil, err
	}

	bodyContent, err := resp.GetBodyContent()

	if err != nil {
		return nil, err
	}

	var bucketSummary *BucketSummary
	err = json.Unmarshal(bodyContent, &bucketSummary)

	if err != nil {
		return nil, err
	}

	return bucketSummary, nil
}
開發者ID:guoyao,項目名稱:baidubce-sdk-go,代碼行數:29,代碼來源:client.go

示例5: AppendObject

func (c *Client) AppendObject(bucketName, objectKey string, offset int, data interface{},
	metadata *ObjectMetadata, option *bce.SignOption) (AppendObjectResponse, error) {

	checkBucketName(bucketName)
	checkObjectKey(objectKey)

	var reader io.Reader

	if str, ok := data.(string); ok {
		reader = strings.NewReader(str)
	} else if byteArray, ok := data.([]byte); ok {
		reader = bytes.NewReader(byteArray)
	} else if r, ok := data.(io.Reader); ok {
		byteArray, err := ioutil.ReadAll(r)

		if err != nil {
			return nil, err
		}

		reader = bytes.NewReader(byteArray)
	} else {
		panic("data type should be string or []byte or io.Reader.")
	}

	params := map[string]string{"append": ""}

	if offset > 0 {
		params["offset"] = strconv.Itoa(offset)
	}

	req, err := bce.NewRequest("POST", c.GetURL(bucketName, objectKey, params), reader)

	if err != nil {
		return nil, err
	}

	option = bce.CheckSignOption(option)
	option.AddHeader("Content-Type", util.GuessMimeType(objectKey))

	if c.Checksum {
		option.AddHeader("x-bce-content-sha256", util.GetSha256(data))
	}

	if metadata != nil {
		metadata.mergeToSignOption(option)
	}

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

	if err != nil {
		return nil, err
	}

	appendObjectResponse := NewAppendObjectResponse(resp.Header)

	return appendObjectResponse, nil
}
開發者ID:guoyao,項目名稱:baidubce-sdk-go,代碼行數:57,代碼來源:client.go

示例6: DeleteBucket

func (c *Client) DeleteBucket(bucketName string, option *bce.SignOption) error {
	req, err := bce.NewRequest("DELETE", c.GetURL(bucketName, "", nil), nil)

	if err != nil {
		return err
	}

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

	return err
}
開發者ID:guoyao,項目名稱:baidubce-sdk-go,代碼行數:11,代碼來源:client.go

示例7: DeleteBucketLogging

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

	if err != nil {
		return err
	}

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

	return err
}
開發者ID:guoyao,項目名稱:baidubce-sdk-go,代碼行數:12,代碼來源:client.go

示例8: DeleteObject

func (c *Client) DeleteObject(bucketName, objectKey string, option *bce.SignOption) error {
	checkObjectKey(objectKey)

	req, err := bce.NewRequest("DELETE", c.GetURL(bucketName, objectKey, nil), nil)

	if err != nil {
		return err
	}

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

	return err
}
開發者ID:guoyao,項目名稱:baidubce-sdk-go,代碼行數:13,代碼來源:client.go

示例9: ListMultipartUploadsFromRequest

func (c *Client) ListMultipartUploadsFromRequest(listMultipartUploadsRequest ListMultipartUploadsRequest,
	option *bce.SignOption) (*ListMultipartUploadsResponse, error) {

	bucketName := listMultipartUploadsRequest.BucketName

	params := map[string]string{"uploads": ""}

	if listMultipartUploadsRequest.Delimiter != "" {
		params["delimiter"] = listMultipartUploadsRequest.Delimiter
	}

	if listMultipartUploadsRequest.KeyMarker != "" {
		params["keyMarker"] = listMultipartUploadsRequest.KeyMarker
	}

	if listMultipartUploadsRequest.Prefix != "" {
		params["prefix"] = listMultipartUploadsRequest.Prefix
	}

	if listMultipartUploadsRequest.MaxUploads > 0 {
		params["maxUploads"] = strconv.Itoa(listMultipartUploadsRequest.MaxUploads)
	}

	req, err := bce.NewRequest("GET", c.GetURL(bucketName, "", params), nil)

	if err != nil {
		return nil, err
	}

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

	if err != nil {
		return nil, err
	}

	bodyContent, err := resp.GetBodyContent()

	if err != nil {
		return nil, err
	}

	var listMultipartUploadsResponse *ListMultipartUploadsResponse

	err = json.Unmarshal(bodyContent, &listMultipartUploadsResponse)

	if err != nil {
		return nil, err
	}

	return listMultipartUploadsResponse, nil
}
開發者ID:guoyao,項目名稱:baidubce-sdk-go,代碼行數:51,代碼來源:client.go

示例10: 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

示例11: 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

示例12: InitiateMultipartUpload

func (c *Client) InitiateMultipartUpload(initiateMultipartUploadRequest InitiateMultipartUploadRequest,
	option *bce.SignOption) (*InitiateMultipartUploadResponse, error) {

	bucketName := initiateMultipartUploadRequest.BucketName
	objectKey := initiateMultipartUploadRequest.ObjectKey

	checkBucketName(bucketName)
	checkObjectKey(objectKey)

	params := map[string]string{"uploads": ""}

	req, err := bce.NewRequest("POST", c.GetURL(bucketName, objectKey, params), nil)

	if err != nil {
		return nil, err
	}

	option = bce.CheckSignOption(option)
	option.AddHeader("Content-Type", util.GuessMimeType(objectKey))

	if initiateMultipartUploadRequest.ObjectMetadata != nil {
		initiateMultipartUploadRequest.ObjectMetadata.mergeToSignOption(option)
	}

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

	if err != nil {
		return nil, err
	}

	bodyContent, err := resp.GetBodyContent()

	if err != nil {
		return nil, err
	}

	var initiateMultipartUploadResponse *InitiateMultipartUploadResponse
	err = json.Unmarshal(bodyContent, &initiateMultipartUploadResponse)

	if err != nil {
		return nil, err
	}

	return initiateMultipartUploadResponse, nil
}
開發者ID:guoyao,項目名稱:baidubce-sdk-go,代碼行數:45,代碼來源:client.go

示例13: SetBucketCors

func (c *Client) SetBucketCors(bucketName string, bucketCors BucketCors, option *bce.SignOption) error {
	byteArray, err := util.ToJson(bucketCors, "corsConfiguration")

	if err != nil {
		return err
	}

	params := map[string]string{"cors": ""}
	req, err := bce.NewRequest("PUT", c.GetURL(bucketName, "", params), bytes.NewReader(byteArray))

	if err != nil {
		return err
	}

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

	return err
}
開發者ID:guoyao,項目名稱:baidubce-sdk-go,代碼行數:18,代碼來源:client.go

示例14: SetBucketAcl

func (c *Client) SetBucketAcl(bucketName string, bucketAcl BucketAcl, option *bce.SignOption) error {
	byteArray, err := util.ToJson(bucketAcl, "accessControlList")

	if err != nil {
		return err
	}

	params := map[string]string{"acl": ""}
	req, err := bce.NewRequest("PUT", c.GetURL(bucketName, "", params), bytes.NewReader(byteArray))

	if err != nil {
		return err
	}

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

	return err
}
開發者ID:guoyao,項目名稱:baidubce-sdk-go,代碼行數:18,代碼來源:client.go

示例15: GeneratePresignedUrl

func (c *Client) GeneratePresignedUrl(bucketName, objectKey string, option *bce.SignOption) (string, error) {
	checkBucketName(bucketName)
	checkObjectKey(objectKey)

	req, err := bce.NewRequest("GET", c.GetURL(bucketName, objectKey, nil), nil)

	if err != nil {
		return "", err
	}

	option = bce.CheckSignOption(option)
	option.HeadersToSign = []string{"host"}

	authorization := bce.GenerateAuthorization(*c.Credentials, *req, option)
	url := fmt.Sprintf("%s?authorization=%s", req.URL.String(), util.URLEncode(authorization))

	return url, nil
}
開發者ID:guoyao,項目名稱:baidubce-sdk-go,代碼行數:18,代碼來源:client.go


注:本文中的github.com/guoyao/baidubce-sdk-go/bce.NewRequest函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。