本文整理汇总了Golang中github.com/guoyao/baidubce-sdk-go/bce.SignOption类的典型用法代码示例。如果您正苦于以下问题:Golang SignOption类的具体用法?Golang SignOption怎么用?Golang SignOption使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SignOption类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
示例2: 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
}
示例3: 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
}
示例4: 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
}
示例5: PutObject
func (c *Client) PutObject(bucketName, objectKey string, data interface{},
metadata *ObjectMetadata, option *bce.SignOption) (PutObjectResponse, error) {
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 {
reader = r
} else {
panic("data type should be string or []byte or io.Reader.")
}
req, err := bce.NewRequest("PUT", c.GetURL(bucketName, objectKey, nil), 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
}
putObjectResponse := NewPutObjectResponse(resp.Header)
return putObjectResponse, nil
}
示例6: CopyObjectFromRequest
func (c *Client) CopyObjectFromRequest(copyObjectRequest CopyObjectRequest,
option *bce.SignOption) (*CopyObjectResponse, error) {
checkBucketName(copyObjectRequest.SrcBucketName)
checkBucketName(copyObjectRequest.DestBucketName)
checkObjectKey(copyObjectRequest.SrcKey)
checkObjectKey(copyObjectRequest.DestKey)
req, err := bce.NewRequest("PUT", c.GetURL(copyObjectRequest.DestBucketName, copyObjectRequest.DestKey, nil), nil)
if err != nil {
return nil, err
}
option = bce.CheckSignOption(option)
source := util.URIEncodeExceptSlash(fmt.Sprintf("/%s/%s", copyObjectRequest.SrcBucketName,
copyObjectRequest.SrcKey))
option.AddHeader("x-bce-copy-source", source)
copyObjectRequest.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 copyObjectResponse *CopyObjectResponse
err = json.Unmarshal(bodyContent, ©ObjectResponse)
if err != nil {
return nil, err
}
return copyObjectResponse, nil
}
示例7: 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
}
示例8: 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")
}
}
示例9: MergeToSignOption
func (getObjectRequest *GetObjectRequest) MergeToSignOption(option *bce.SignOption) {
if getObjectRequest.Range != "" {
option.AddHeader("Range", "bytes="+getObjectRequest.Range)
}
}