diff --git a/http/client.go b/http/client.go index b036a403..7d2393ab 100644 --- a/http/client.go +++ b/http/client.go @@ -106,26 +106,27 @@ func InitClient(config ClientConfig) { // - response: the http response returned from the server // - error: nil if ok otherwise the specific error func Execute(request *Request) (*Response, error) { - // Build the request object for the current requesting - httpRequest := &http.Request{ - Proto: "HTTP/1.1", - ProtoMajor: 1, - ProtoMinor: 1, - } - - // Set the connection timeout for current request - httpClient.Timeout = time.Duration(request.Timeout()) * time.Second - - // Set the request method - httpRequest.Method = request.Method() - // Set the request url internalUrl := &url.URL{ Scheme: request.Protocol(), Host: request.Host(), Path: request.Uri(), - RawQuery: request.QueryString()} - httpRequest.URL = internalUrl + RawQuery: request.QueryString(), + } + + // Build the request object for the current requesting + httpRequest, err := http.NewRequestWithContext( + request.Context(), + request.Method(), + internalUrl.String(), + nil, + ) + if err != nil { + return nil, err + } + + // Set the connection timeout for current request + httpClient.Timeout = time.Duration(request.Timeout()) * time.Second // Set the request headers internalHeader := make(http.Header) diff --git a/http/request.go b/http/request.go index 7fecfb99..199b13f6 100644 --- a/http/request.go +++ b/http/request.go @@ -17,6 +17,7 @@ package http import ( + "context" "fmt" "io" "strconv" @@ -40,6 +41,8 @@ type Request struct { // Optional body and length fields to set the body stream and content length body io.ReadCloser length int64 + + ctx context.Context } func (r *Request) Protocol() string { @@ -211,6 +214,17 @@ func (r *Request) GenerateUrl(addPort bool) string { } } +func (r *Request) Context() context.Context { + if r.ctx != nil { + return r.ctx + } + return context.Background() +} + +func (r *Request) SetContext(ctx context.Context) { + r.ctx = ctx +} + func (r *Request) String() string { header := make([]string, 0, len(r.headers)) for k, v := range r.headers { diff --git a/services/bos/api/bucket.go b/services/bos/api/bucket.go index 261ac06e..f0a62382 100644 --- a/services/bos/api/bucket.go +++ b/services/bos/api/bucket.go @@ -18,6 +18,7 @@ package api import ( + "context" "encoding/json" "strconv" @@ -33,7 +34,20 @@ import ( // - *ListBucketsResult: the result bucket list structure // - error: nil if ok otherwise the specific error func ListBuckets(cli bce.Client) (*ListBucketsResult, error) { + return ListBucketsWithContext(context.Background(), cli) +} + +// ListBucketsWithContext - list all buckets of the account +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// RETURNS: +// - *ListBucketsResult: the result bucket list structure +// - error: nil if ok otherwise the specific error +func ListBucketsWithContext(ctx context.Context, cli bce.Client) (*ListBucketsResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetMethod(http.GET) resp := &bce.BceResponse{} if err := SendRequest(cli, req, resp); err != nil { @@ -59,8 +73,24 @@ func ListBuckets(cli bce.Client) (*ListBucketsResult, error) { // - *ListObjectsResult: the result object list structure // - error: nil if ok otherwise the specific error func ListObjects(cli bce.Client, bucket string, + args *ListObjectsArgs) (*ListObjectsResult, error) { + return ListObjectsWithContext(context.Background(), cli, bucket, args) +} + +// ListObjectsWithContext - list all objects of the given bucket +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - args: the optional arguments to list objects +// RETURNS: +// - *ListObjectsResult: the result object list structure +// - error: nil if ok otherwise the specific error +func ListObjectsWithContext(ctx context.Context, cli bce.Client, bucket string, args *ListObjectsArgs) (*ListObjectsResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) @@ -107,7 +137,20 @@ func ListObjects(cli bce.Client, bucket string, // RETURNS: // - error: nil if exists and have authority otherwise the specific error func HeadBucket(cli bce.Client, bucket string) (error, *bce.BceResponse) { + return HeadBucketWithContext(context.Background(), cli, bucket) +} + +// HeadBucketWithContext - test the given bucket existed and access authority +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - error: nil if exists and have authority otherwise the specific error +func HeadBucketWithContext(ctx context.Context, cli bce.Client, bucket string) (error, *bce.BceResponse) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.HEAD) resp := &bce.BceResponse{} @@ -121,7 +164,6 @@ func HeadBucket(cli bce.Client, bucket string) (error, *bce.BceResponse) { return nil, resp } - // PutBucket - create a new bucket with the given name // // PARAMS: @@ -131,7 +173,21 @@ func HeadBucket(cli bce.Client, bucket string) (error, *bce.BceResponse) { // - string: the location of the new bucket if create success // - error: nil if create success otherwise the specific error func PutBucket(cli bce.Client, bucket string) (string, error) { + return PutBucketWithContext(context.Background(), cli, bucket) +} + +// PutBucketWithContext - create a new bucket with the given name +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the new bucket name +// RETURNS: +// - string: the location of the new bucket if create success +// - error: nil if create success otherwise the specific error +func PutBucketWithContext(ctx context.Context, cli bce.Client, bucket string) (string, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) resp := &bce.BceResponse{} @@ -153,7 +209,20 @@ func PutBucket(cli bce.Client, bucket string) (string, error) { // RETURNS: // - error: nil if delete success otherwise the specific error func DeleteBucket(cli bce.Client, bucket string) error { + return DeleteBucketWithContext(context.Background(), cli, bucket) +} + +// DeleteBucketWithContext - delete an empty bucket by given name +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name to be deleted +// RETURNS: +// - error: nil if delete success otherwise the specific error +func DeleteBucketWithContext(ctx context.Context, cli bce.Client, bucket string) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) resp := &bce.BceResponse{} @@ -176,7 +245,21 @@ func DeleteBucket(cli bce.Client, bucket string) error { // - string: the location of the bucket // - error: nil if delete success otherwise the specific error func GetBucketLocation(cli bce.Client, bucket string) (string, error) { + return GetBucketLocationWithContext(context.Background(), cli, bucket) +} + +// GetBucketLocationWithContext - get the location of the given bucket +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - string: the location of the bucket +// - error: nil if delete success otherwise the specific error +func GetBucketLocationWithContext(ctx context.Context, cli bce.Client, bucket string) (string, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("location", "") @@ -205,7 +288,22 @@ func GetBucketLocation(cli bce.Client, bucket string) (string, error) { // RETURNS: // - error: nil if delete success otherwise the specific error func PutBucketAcl(cli bce.Client, bucket, cannedAcl string, aclBody *bce.Body) error { + return PutBucketAclWithContext(context.Background(), cli, bucket, cannedAcl, aclBody) +} + +// PutBucketAclWithContext - set the acl of the given bucket +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - cannedAcl: support private, public-read, public-read-write +// - aclBody: the acl file body +// RETURNS: +// - error: nil if delete success otherwise the specific error +func PutBucketAclWithContext(ctx context.Context, cli bce.Client, bucket, cannedAcl string, aclBody *bce.Body) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("acl", "") @@ -221,7 +319,6 @@ func PutBucketAcl(cli bce.Client, bucket, cannedAcl string, aclBody *bce.Body) e req.SetHeader(http.CONTENT_TYPE, bce.DEFAULT_CONTENT_TYPE) req.SetBody(aclBody) } - resp := &bce.BceResponse{} if err := SendRequest(cli, req, resp); err != nil { return err @@ -242,7 +339,21 @@ func PutBucketAcl(cli bce.Client, bucket, cannedAcl string, aclBody *bce.Body) e // - *GetBucketAclResult: the result of the bucket acl // - error: nil if success otherwise the specific error func GetBucketAcl(cli bce.Client, bucket string) (*GetBucketAclResult, error) { + return GetBucketAclWithContext(context.Background(), cli, bucket) +} + +// GetBucketAclWithContext - get the acl of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - *GetBucketAclResult: the result of the bucket acl +// - error: nil if success otherwise the specific error +func GetBucketAclWithContext(ctx context.Context, cli bce.Client, bucket string) (*GetBucketAclResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("acl", "") @@ -271,7 +382,21 @@ func GetBucketAcl(cli bce.Client, bucket string) (*GetBucketAclResult, error) { // RETURNS: // - error: nil if success otherwise the specific error func PutBucketLogging(cli bce.Client, bucket string, logging *bce.Body) error { + return PutBucketLoggingWithContext(context.Background(), cli, bucket, logging) +} + +// PutBucketLoggingWithContext - set the logging prefix of the given bucket +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - logging: the logging prefix json string body +// RETURNS: +// - error: nil if success otherwise the specific error +func PutBucketLoggingWithContext(ctx context.Context, cli bce.Client, bucket string, logging *bce.Body) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("logging", "") @@ -296,7 +421,21 @@ func PutBucketLogging(cli bce.Client, bucket string, logging *bce.Body) error { // - *GetBucketLoggingResult: the logging setting of the bucket // - error: nil if success otherwise the specific error func GetBucketLogging(cli bce.Client, bucket string) (*GetBucketLoggingResult, error) { + return GetBucketLoggingWithContext(context.Background(), cli, bucket) +} + +// GetBucketLoggingWithContext - get the logging config of the given bucket +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - *GetBucketLoggingResult: the logging setting of the bucket +// - error: nil if success otherwise the specific error +func GetBucketLoggingWithContext(ctx context.Context, cli bce.Client, bucket string) (*GetBucketLoggingResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("logging", "") @@ -323,7 +462,20 @@ func GetBucketLogging(cli bce.Client, bucket string) (*GetBucketLoggingResult, e // RETURNS: // - error: nil if success otherwise the specific error func DeleteBucketLogging(cli bce.Client, bucket string) error { + return DeleteBucketLoggingWithContext(context.Background(), cli, bucket) +} + +// DeleteBucketLoggingWithContext - delete the logging setting of the given bucket +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - error: nil if success otherwise the specific error +func DeleteBucketLoggingWithContext(ctx context.Context, cli bce.Client, bucket string) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("logging", "") @@ -347,7 +499,21 @@ func DeleteBucketLogging(cli bce.Client, bucket string) error { // RETURNS: // - error: nil if success otherwise the specific error func PutBucketLifecycle(cli bce.Client, bucket string, lifecycle *bce.Body) error { + return PutBucketLifecycleWithContext(context.Background(), cli, bucket, lifecycle) +} + +// PutBucketLifecycleWithContext - set the lifecycle rule of the given bucket +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - lifecycle: the lifecycle rule json string body +// RETURNS: +// - error: nil if success otherwise the specific error +func PutBucketLifecycleWithContext(ctx context.Context, cli bce.Client, bucket string, lifecycle *bce.Body) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("lifecycle", "") @@ -372,7 +538,21 @@ func PutBucketLifecycle(cli bce.Client, bucket string, lifecycle *bce.Body) erro // - *GetBucketLifecycleResult: the lifecycle rule of the bucket // - error: nil if success otherwise the specific error func GetBucketLifecycle(cli bce.Client, bucket string) (*GetBucketLifecycleResult, error) { + return GetBucketLifecycleWithContext(context.Background(), cli, bucket) +} + +// GetBucketLifecycleWithContext - get the lifecycle rule of the given bucket +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - *GetBucketLifecycleResult: the lifecycle rule of the bucket +// - error: nil if success otherwise the specific error +func GetBucketLifecycleWithContext(ctx context.Context, cli bce.Client, bucket string) (*GetBucketLifecycleResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("lifecycle", "") @@ -399,7 +579,20 @@ func GetBucketLifecycle(cli bce.Client, bucket string) (*GetBucketLifecycleResul // RETURNS: // - error: nil if success otherwise the specific error func DeleteBucketLifecycle(cli bce.Client, bucket string) error { + return DeleteBucketLifecycleWithContext(context.Background(), cli, bucket) +} + +// DeleteBucketLifecycleWithContext - delete the lifecycle rule of the given bucket +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - error: nil if success otherwise the specific error +func DeleteBucketLifecycleWithContext(ctx context.Context, cli bce.Client, bucket string) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("lifecycle", "") @@ -423,7 +616,21 @@ func DeleteBucketLifecycle(cli bce.Client, bucket string) error { // RETURNS: // - error: nil if success otherwise the specific error func PutBucketStorageclass(cli bce.Client, bucket, storageClass string) error { + return PutBucketStorageclassWithContext(context.Background(), cli, bucket, storageClass) +} + +// PutBucketStorageclassWithContext - set the storage class of the given bucket +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - storageClass: the storage class string +// RETURNS: +// - error: nil if success otherwise the specific error +func PutBucketStorageclassWithContext(ctx context.Context, cli bce.Client, bucket, storageClass string) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("storageClass", "") @@ -459,7 +666,21 @@ func PutBucketStorageclass(cli bce.Client, bucket, storageClass string) error { // - string: the storage class of the bucket // - error: nil if success otherwise the specific error func GetBucketStorageclass(cli bce.Client, bucket string) (string, error) { + return GetBucketStorageclassWithContext(context.Background(), cli, bucket) +} + +// GetBucketStorageclassWithContext - get the storage class of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - string: the storage class of the bucket +// - error: nil if success otherwise the specific error +func GetBucketStorageclassWithContext(ctx context.Context, cli bce.Client, bucket string) (string, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("storageClass", "") @@ -488,7 +709,22 @@ func GetBucketStorageclass(cli bce.Client, bucket string) (string, error) { // RETURNS: // - error: nil if success otherwise the specific error func PutBucketReplication(cli bce.Client, bucket string, replicationConf *bce.Body, replicationRuleId string) error { + return PutBucketReplicationWithContext(context.Background(), cli, bucket, replicationConf, replicationRuleId) +} + +// PutBucketReplicationWithContext - set the bucket replication of different region +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - replicationConf: the replication config body stream +// - replicationRuleId: the replication rule id composed of [0-9 A-Z a-z _ -] +// RETURNS: +// - error: nil if success otherwise the specific error +func PutBucketReplicationWithContext(ctx context.Context, cli bce.Client, bucket string, replicationConf *bce.Body, replicationRuleId string) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("replication", "") @@ -522,7 +758,22 @@ func PutBucketReplication(cli bce.Client, bucket string, replicationConf *bce.Bo // - *GetBucketReplicationResult: the result of the bucket replication config // - error: nil if success otherwise the specific error func GetBucketReplication(cli bce.Client, bucket string, replicationRuleId string) (*GetBucketReplicationResult, error) { + return GetBucketReplicationWithContext(context.Background(), cli, bucket, replicationRuleId) +} + +// GetBucketReplicationWithContext - get the bucket replication config of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - replicationRuleId: the replication rule id composed of [0-9 A-Z a-z _ -] +// RETURNS: +// - *GetBucketReplicationResult: the result of the bucket replication config +// - error: nil if success otherwise the specific error +func GetBucketReplicationWithContext(ctx context.Context, cli bce.Client, bucket string, replicationRuleId string) (*GetBucketReplicationResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("replication", "") @@ -552,7 +803,20 @@ func GetBucketReplication(cli bce.Client, bucket string, replicationRuleId strin // RETURNS: // - error: nil if success otherwise the specific error func ListBucketReplication(cli bce.Client, bucket string) (*ListBucketReplicationResult, error) { + return ListBucketReplicationWithContext(context.Background(), cli, bucket) +} + +// ListBucketReplicationWithContext - list all replication config of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - error: nil if success otherwise the specific error +func ListBucketReplicationWithContext(ctx context.Context, cli bce.Client, bucket string) (*ListBucketReplicationResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("replication", "") @@ -580,7 +844,21 @@ func ListBucketReplication(cli bce.Client, bucket string) (*ListBucketReplicatio // RETURNS: // - error: nil if success otherwise the specific error func DeleteBucketReplication(cli bce.Client, bucket string, replicationRuleId string) error { + return DeleteBucketReplicationWithContext(context.Background(), cli, bucket, replicationRuleId) +} + +// DeleteBucketReplicationWithContext - delete the bucket replication config of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - replicationRuleId: the replication rule id composed of [0-9 A-Z a-z _ -] +// RETURNS: +// - error: nil if success otherwise the specific error +func DeleteBucketReplicationWithContext(ctx context.Context, cli bce.Client, bucket string, replicationRuleId string) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("replication", "") @@ -608,8 +886,24 @@ func DeleteBucketReplication(cli bce.Client, bucket string, replicationRuleId st // - *GetBucketReplicationProgressResult: the result of the bucket replication process // - error: nil if success otherwise the specific error func GetBucketReplicationProgress(cli bce.Client, bucket string, replicationRuleId string) ( + *GetBucketReplicationProgressResult, error) { + return GetBucketReplicationProgressWithContext(context.Background(), cli, bucket, replicationRuleId) +} + +// GetBucketReplicationProgressWithContext - get the bucket replication process of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - replicationRuleId: the replication rule id composed of [0-9 A-Z a-z _ -] +// RETURNS: +// - *GetBucketReplicationProgressResult: the result of the bucket replication process +// - error: nil if success otherwise the specific error +func GetBucketReplicationProgressWithContext(ctx context.Context, cli bce.Client, bucket string, replicationRuleId string) ( *GetBucketReplicationProgressResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("replicationProgress", "") @@ -631,7 +925,7 @@ func GetBucketReplicationProgress(cli bce.Client, bucket string, replicationRule return result, nil } -// PutBucketEncryption - set the bucket encrpytion config +// PutBucketEncryption - set the bucket encrpytion config of the given bucket // // PARAMS: // - cli: the client agent which can perform sending request @@ -640,7 +934,21 @@ func GetBucketReplicationProgress(cli bce.Client, bucket string, replicationRule // RETURNS: // - error: nil if success otherwise the specific error func PutBucketEncryption(cli bce.Client, bucket, algorithm string) error { + return PutBucketEncryptionWithContext(context.Background(), cli, bucket, algorithm) +} + +// PutBucketEncryptionWithContext - set the bucket encrpytion config of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - algorithm: the encryption algorithm +// RETURNS: +// - error: nil if success otherwise the specific error +func PutBucketEncryptionWithContext(ctx context.Context, cli bce.Client, bucket, algorithm string) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("encryption", "") @@ -677,7 +985,21 @@ func PutBucketEncryption(cli bce.Client, bucket, algorithm string) error { // - algorithm: the bucket encryption algorithm // - error: nil if success otherwise the specific error func GetBucketEncryption(cli bce.Client, bucket string) (string, error) { + return GetBucketEncryptionWithContext(context.Background(), cli, bucket) +} + +// GetBucketEncryptionWithContext - get the encryption config of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - algorithm: the bucket encryption algorithm +// - error: nil if success otherwise the specific error +func GetBucketEncryptionWithContext(ctx context.Context, cli bce.Client, bucket string) (string, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("encryption", "") @@ -704,7 +1026,20 @@ func GetBucketEncryption(cli bce.Client, bucket string) (string, error) { // RETURNS: // - error: nil if success otherwise the specific error func DeleteBucketEncryption(cli bce.Client, bucket string) error { + return DeleteBucketEncryptionWithContext(context.Background(), cli, bucket) +} + +// DeleteBucketEncryption - delete the encryption config of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - error: nil if success otherwise the specific error +func DeleteBucketEncryptionWithContext(ctx context.Context, cli bce.Client, bucket string) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("encryption", "") @@ -728,7 +1063,21 @@ func DeleteBucketEncryption(cli bce.Client, bucket string) error { // RETURNS: // - error: nil if success otherwise the specific error func PutBucketStaticWebsite(cli bce.Client, bucket string, confBody *bce.Body) error { + return PutBucketStaticWebsiteWithContext(context.Background(), cli, bucket, confBody) +} + +// PutBucketStaticWebsiteWithContext - set the bucket static website config +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - confBody: the static website config body stream +// RETURNS: +// - error: nil if success otherwise the specific error +func PutBucketStaticWebsiteWithContext(ctx context.Context, cli bce.Client, bucket string, confBody *bce.Body) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("website", "") @@ -757,8 +1106,23 @@ func PutBucketStaticWebsite(cli bce.Client, bucket string, confBody *bce.Body) e // - result: the bucket static website config result object // - error: nil if success otherwise the specific error func GetBucketStaticWebsite(cli bce.Client, bucket string) ( + *GetBucketStaticWebsiteResult, error) { + return GetBucketStaticWebsiteWithContext(context.Background(), cli, bucket) +} + +// GetBucketStaticWebsiteWithContext - get the static website config of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - result: the bucket static website config result object +// - error: nil if success otherwise the specific error +func GetBucketStaticWebsiteWithContext(ctx context.Context, cli bce.Client, bucket string) ( *GetBucketStaticWebsiteResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("website", "") @@ -785,7 +1149,20 @@ func GetBucketStaticWebsite(cli bce.Client, bucket string) ( // RETURNS: // - error: nil if success otherwise the specific error func DeleteBucketStaticWebsite(cli bce.Client, bucket string) error { + return DeleteBucketStaticWebsiteWithContext(context.Background(), cli, bucket) +} + +// DeleteBucketStaticWebsiteWithContext - delete the static website config of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - error: nil if success otherwise the specific error +func DeleteBucketStaticWebsiteWithContext(ctx context.Context, cli bce.Client, bucket string) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("website", "") @@ -809,7 +1186,21 @@ func DeleteBucketStaticWebsite(cli bce.Client, bucket string) error { // RETURNS: // - error: nil if success otherwise the specific error func PutBucketCors(cli bce.Client, bucket string, confBody *bce.Body) error { + return PutBucketCorsWithContext(context.Background(), cli, bucket, confBody) +} + +// PutBucketCorsWithContext - set the bucket CORS config +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - confBody: the CORS config body stream +// RETURNS: +// - error: nil if success otherwise the specific error +func PutBucketCorsWithContext(ctx context.Context, cli bce.Client, bucket string, confBody *bce.Body) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("cors", "") @@ -838,8 +1229,23 @@ func PutBucketCors(cli bce.Client, bucket string, confBody *bce.Body) error { // - result: the bucket CORS config result object // - error: nil if success otherwise the specific error func GetBucketCors(cli bce.Client, bucket string) ( + *GetBucketCorsResult, error) { + return GetBucketCorsWithContext(context.Background(), cli, bucket) +} + +// GetBucketCorsWithContext - get the CORS config of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - result: the bucket CORS config result object +// - error: nil if success otherwise the specific error +func GetBucketCorsWithContext(ctx context.Context, cli bce.Client, bucket string) ( *GetBucketCorsResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("cors", "") @@ -866,7 +1272,20 @@ func GetBucketCors(cli bce.Client, bucket string) ( // RETURNS: // - error: nil if success otherwise the specific error func DeleteBucketCors(cli bce.Client, bucket string) error { + return DeleteBucketCorsWithContext(context.Background(), cli, bucket) +} + +// DeleteBucketCorsWithContext - delete the CORS config of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - error: nil if success otherwise the specific error +func DeleteBucketCorsWithContext(ctx context.Context, cli bce.Client, bucket string) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("cors", "") @@ -890,7 +1309,21 @@ func DeleteBucketCors(cli bce.Client, bucket string) error { // RETURNS: // - error: nil if success otherwise the specific error func PutBucketCopyrightProtection(cli bce.Client, bucket string, resources ...string) error { + return PutBucketCopyrightProtectionWithContext(context.Background(), cli, bucket, resources...) +} + +// PutBucketCopyrightProtectionWithContext - set the copyright protection config of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - resources: the resource items in the bucket to be protected +// RETURNS: +// - error: nil if success otherwise the specific error +func PutBucketCopyrightProtectionWithContext(ctx context.Context, cli bce.Client, bucket string, resources ...string) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("copyrightProtection", "") @@ -929,7 +1362,21 @@ func PutBucketCopyrightProtection(cli bce.Client, bucket string, resources ...st // - result: the bucket copyright protection resources array // - error: nil if success otherwise the specific error func GetBucketCopyrightProtection(cli bce.Client, bucket string) ([]string, error) { + return GetBucketCopyrightProtectionWithContext(context.Background(), cli, bucket) +} + +// GetBucketCopyrightProtectionWithContext - get the copyright protection config of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - result: the bucket copyright protection resources array +// - error: nil if success otherwise the specific error +func GetBucketCopyrightProtectionWithContext(ctx context.Context, cli bce.Client, bucket string) ([]string, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("copyrightProtection", "") @@ -956,7 +1403,20 @@ func GetBucketCopyrightProtection(cli bce.Client, bucket string) ([]string, erro // RETURNS: // - error: nil if success otherwise the specific error func DeleteBucketCopyrightProtection(cli bce.Client, bucket string) error { + return DeleteBucketCopyrightProtectionWithContext(context.Background(), cli, bucket) +} + +// DeleteBucketCopyrightProtectionWithContext - delete the copyright protection config of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// RETURNS: +// - error: nil if success otherwise the specific error +func DeleteBucketCopyrightProtectionWithContext(ctx context.Context, cli bce.Client, bucket string) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("copyrightProtection", "") @@ -980,7 +1440,22 @@ func DeleteBucketCopyrightProtection(cli bce.Client, bucket string) error { // RETURNS: // - error: nil if success otherwise the specific error func PutBucketTrash(cli bce.Client, bucket string, trashReq PutBucketTrashReq) error { + return PutBucketTrashWithContext(context.Background(), cli, bucket, trashReq) +} + +// PutBucketTrashWithContext - put the trash setting of the given bucket +// +// PARAMS: +// - context: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - trashDir: the trash dir name +// RETURNS: +// - error: nil if success otherwise the specific error +func PutBucketTrashWithContext(ctx context.Context, cli bce.Client, bucket string, + trashReq PutBucketTrashReq) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("trash", "") @@ -1002,7 +1477,12 @@ func PutBucketTrash(cli bce.Client, bucket string, trashReq PutBucketTrashReq) e } func GetBucketTrash(cli bce.Client, bucket string) (*GetBucketTrashResult, error) { + return GetBucketTrashWithContext(context.Background(), cli, bucket) +} + +func GetBucketTrashWithContext(ctx context.Context, cli bce.Client, bucket string) (*GetBucketTrashResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("trash", "") @@ -1021,7 +1501,12 @@ func GetBucketTrash(cli bce.Client, bucket string) (*GetBucketTrashResult, error } func DeleteBucketTrash(cli bce.Client, bucket string) error { + return DeleteBucketTrashWithContext(context.Background(), cli, bucket) +} + +func DeleteBucketTrashWithContext(ctx context.Context, cli bce.Client, bucket string) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("trash", "") @@ -1037,7 +1522,13 @@ func DeleteBucketTrash(cli bce.Client, bucket string) error { } func PutBucketNotification(cli bce.Client, bucket string, putBucketNotificationReq PutBucketNotificationReq) error { + return PutBucketNotificationWithContext(context.Background(), cli, bucket, putBucketNotificationReq) +} + +func PutBucketNotificationWithContext(ctx context.Context, cli bce.Client, bucket string, + putBucketNotificationReq PutBucketNotificationReq) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.PUT) req.SetParam("notification", "") @@ -1059,7 +1550,12 @@ func PutBucketNotification(cli bce.Client, bucket string, putBucketNotificationR } func GetBucketNotification(cli bce.Client, bucket string) (*PutBucketNotificationReq, error) { + return GetBucketNotificationWithContext(context.Background(), cli, bucket) +} + +func GetBucketNotificationWithContext(ctx context.Context, cli bce.Client, bucket string) (*PutBucketNotificationReq, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.GET) req.SetParam("notification", "") @@ -1078,7 +1574,12 @@ func GetBucketNotification(cli bce.Client, bucket string) (*PutBucketNotificatio } func DeleteBucketNotification(cli bce.Client, bucket string) error { + return DeleteBucketNotificationWithContext(context.Background(), cli, bucket) +} + +func DeleteBucketNotificationWithContext(ctx context.Context, cli bce.Client, bucket string) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.DELETE) req.SetParam("notification", "") diff --git a/services/bos/api/object.go b/services/bos/api/object.go index cbb91ce6..277271a5 100644 --- a/services/bos/api/object.go +++ b/services/bos/api/object.go @@ -17,6 +17,7 @@ package api import ( + "context" "encoding/json" "fmt" "net" @@ -41,8 +42,26 @@ import ( // - string: the etag of the object // - error: nil if ok otherwise the specific error func PutObject(cli bce.Client, bucket, object string, body *bce.Body, + args *PutObjectArgs) (string, error) { + return PutObjectWithContext(context.Background(), cli, bucket, object, body, args) +} + +// PutObjectWithContext - put the object from the string or the stream +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name of the object +// - object: the name of the object +// - body: the input content of the object +// - args: the optional arguments of this api +// RETURNS: +// - string: the etag of the object +// - error: nil if ok otherwise the specific error +func PutObjectWithContext(ctx context.Context, cli bce.Client, bucket, object string, body *bce.Body, args *PutObjectArgs) (string, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.PUT) if body == nil { @@ -137,8 +156,27 @@ func PutObject(cli bce.Client, bucket, object string, body *bce.Body, // - *CopyObjectResult: the result object which contains etag and lastmodified // - error: nil if ok otherwise the specific error func CopyObject(cli bce.Client, bucket, object, source string, + args *CopyObjectArgs) (*CopyObjectResult, error) { + return CopyObjectWithContext(context.Background(), cli, bucket, object, source, args) +} + +// CopyObjectWithContext - copy one object to a new object with new bucket and/or name. It can alse set the +// metadata of the object with the same source and target. +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client object which can perform sending request +// - bucket: the bucket name of the target object +// - object: the name of the target object +// - source: the source object uri +// - *CopyObjectArgs: the optional input args for copying object +// RETURNS: +// - *CopyObjectResult: the result object which contains etag and lastmodified +// - error: nil if ok otherwise the specific error +func CopyObjectWithContext(ctx context.Context, cli bce.Client, bucket, object, source string, args *CopyObjectArgs) (*CopyObjectResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.PUT) if len(source) == 0 { @@ -227,12 +265,29 @@ func CopyObject(cli bce.Client, bucket, object, source string, // - error: nil if ok otherwise the specific error func GetObject(cli bce.Client, bucket, object string, args map[string]string, // nolint:gocyclo ranges ...int64) (*GetObjectResult, error) { + return GetObjectWithContext(context.Background(), cli, bucket, object, args, ranges...) +} +// GetObjectWithContext - get the object content with range and response-headers-specified support +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name of the object +// - object: the name of the object +// - args: the optional args in querysring +// - ranges: the optional range start and end to get the given object +// RETURNS: +// - *GetObjectResult: the output content result of the object +// - error: nil if ok otherwise the specific error +func GetObjectWithContext(ctx context.Context, cli bce.Client, bucket, object string, args map[string]string, // nolint:gocyclo + ranges ...int64) (*GetObjectResult, error) { if object == "" { err := fmt.Errorf("Get Object don't accept \"\" as a parameter") return nil, err } req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.GET) @@ -340,7 +395,22 @@ func GetObject(cli bce.Client, bucket, object string, args map[string]string, // // - *GetObjectMetaResult: the result of this api // - error: nil if ok otherwise the specific error func GetObjectMeta(cli bce.Client, bucket, object string) (*GetObjectMetaResult, error) { + return GetObjectMetaWithContext(context.Background(), cli, bucket, object) +} + +// GetObjectMetaWithContext - get the meta data of the given object +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name of the object +// - object: the name of the object +// RETURNS: +// - *GetObjectMetaResult: the result of this api +// - error: nil if ok otherwise the specific error +func GetObjectMetaWithContext(ctx context.Context, cli bce.Client, bucket, object string) (*GetObjectMetaResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.HEAD) @@ -431,7 +501,23 @@ func GetObjectMeta(cli bce.Client, bucket, object string) (*GetObjectMetaResult, // - *SelectObjectResult: the output select content result of the object // - error: nil if ok otherwise the specific error func SelectObject(cli bce.Client, bucket, object string, args *SelectObjectArgs) (*SelectObjectResult, error) { + return SelectObjectWithContext(context.Background(), cli, bucket, object, args) +} + +// SelectObjectWithContext - select the object content +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name of the object +// - object: the name of the object +// - args: the optional arguments to perform the select operation +// RETURNS: +// - *SelectObjectResult: the output select content result of the object +// - error: nil if ok otherwise the specific error +func SelectObjectWithContext(ctx context.Context, cli bce.Client, bucket, object string, args *SelectObjectArgs) (*SelectObjectResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.POST) req.SetParam("select", "") @@ -474,8 +560,26 @@ func SelectObject(cli bce.Client, bucket, object string, args *SelectObjectArgs) // - *FetchObjectArgs: the result of this api // - error: nil if ok otherwise the specific error func FetchObject(cli bce.Client, bucket, object, source string, + args *FetchObjectArgs) (*FetchObjectResult, error) { + return FetchObjectWithContext(context.Background(), cli, bucket, object, source, args) +} + +// FetchObjectWithContext - fetch the object by the given url and store it to a bucket +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name to store the object +// - object: the name of the object to be stored +// - source: the source url to fetch +// - args: the optional arguments to perform the fetch operation +// RETURNS: +// - *FetchObjectArgs: the result of this api +// - error: nil if ok otherwise the specific error +func FetchObjectWithContext(ctx context.Context, cli bce.Client, bucket, object, source string, args *FetchObjectArgs) (*FetchObjectResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.POST) req.SetParam("fetch", "") @@ -530,8 +634,26 @@ func FetchObject(cli bce.Client, bucket, object, source string, // - *AppendObjectResult: the result status for this api // - error: nil if ok otherwise the specific error func AppendObject(cli bce.Client, bucket, object string, content *bce.Body, + args *AppendObjectArgs) (*AppendObjectResult, error) { + return AppendObjectWithContext(context.Background(), cli, bucket, object, content, args) +} + +// AppendObjectWithContext - append the given content to a new or existed object which is appendable +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name of the object +// - object: the name of the object +// - content: the content to be appended +// - args: the optional arguments to perform the append operation +// RETURNS: +// - *AppendObjectResult: the result status for this api +// - error: nil if ok otherwise the specific error +func AppendObjectWithContext(ctx context.Context, cli bce.Client, bucket, object string, content *bce.Body, args *AppendObjectArgs) (*AppendObjectResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.POST) req.SetParam("append", "") @@ -623,7 +745,21 @@ func AppendObject(cli bce.Client, bucket, object string, content *bce.Body, // RETURNS: // - error: nil if ok otherwise the specific error func DeleteObject(cli bce.Client, bucket, object string) error { + return DeleteObjectWithContext(context.Background(), cli, bucket, object) +} + +// DeleteObjectWithContext - delete the given object +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name of the object to be deleted +// - object: the name of the object +// RETURNS: +// - error: nil if ok otherwise the specific error +func DeleteObjectWithContext(ctx context.Context, cli bce.Client, bucket, object string) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.DELETE) @@ -648,8 +784,24 @@ func DeleteObject(cli bce.Client, bucket, object string) error { // - *DeleteMultipleObjectsResult: the objects failed to delete // - error: nil if ok otherwise the specific error func DeleteMultipleObjects(cli bce.Client, bucket string, + objectListStream *bce.Body) (*DeleteMultipleObjectsResult, error) { + return DeleteMultipleObjectsWithContext(context.Background(), cli, bucket, objectListStream) +} + +// DeleteMultipleObjectsWithContext - delete the given objects within a single http request +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name of the objects to be deleted +// - objectListStream: the objects list to be delete with json format +// RETURNS: +// - *DeleteMultipleObjectsResult: the objects failed to delete +// - error: nil if ok otherwise the specific error +func DeleteMultipleObjectsWithContext(ctx context.Context, cli bce.Client, bucket string, objectListStream *bce.Body) (*DeleteMultipleObjectsResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getBucketUri(bucket)) req.SetMethod(http.POST) req.SetParam("delete", "") @@ -775,8 +927,27 @@ func GeneratePresignedUrlInternal(conf *bce.BceClientConfiguration, signer auth. // RETURNS: // - error: nil if success otherwise the specific error func PutObjectAcl(cli bce.Client, bucket, object, cannedAcl string, + grantRead, grantFullControl []string, aclBody *bce.Body) error { + return PutObjectAclWithContext(context.Background(), cli, bucket, object, cannedAcl, grantRead, grantFullControl, aclBody) +} + +// PutObjectAclWithContext - set the ACL of the given object with context +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - object: the object name +// - cannedAcl: support private and public-read +// - grantRead: user id list +// - grantFullControl: user id list +// - aclBody: the acl file body +// RETURNS: +// - error: nil if success otherwise the specific error +func PutObjectAclWithContext(ctx context.Context, cli bce.Client, bucket, object, cannedAcl string, grantRead, grantFullControl []string, aclBody *bce.Body) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.PUT) req.SetParam("acl", "") @@ -836,7 +1007,22 @@ func PutObjectAcl(cli bce.Client, bucket, object, cannedAcl string, // - result: the object acl result object // - error: nil if success otherwise the specific error func GetObjectAcl(cli bce.Client, bucket, object string) (*GetObjectAclResult, error) { + return GetObjectAclWithContext(context.Background(), cli, bucket, object) +} + +// GetObjectAclWithContext - get the ACL of the given object with context +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - object: the object name +// RETURNS: +// - result: the object acl result object +// - error: nil if success otherwise the specific error +func GetObjectAclWithContext(ctx context.Context, cli bce.Client, bucket, object string) (*GetObjectAclResult, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.GET) req.SetParam("acl", "") @@ -864,7 +1050,21 @@ func GetObjectAcl(cli bce.Client, bucket, object string) (*GetObjectAclResult, e // RETURNS: // - error: nil if success otherwise the specific error func DeleteObjectAcl(cli bce.Client, bucket, object string) error { + return DeleteObjectAclWithContext(context.Background(), cli, bucket, object) +} + +// DeleteObjectAclWithContext - delete the ACL of the given object with context +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - object: the object name +// RETURNS: +// - error: nil if success otherwise the specific error +func DeleteObjectAclWithContext(ctx context.Context, cli bce.Client, bucket, object string) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getObjectUri(bucket, object)) req.SetMethod(http.DELETE) req.SetParam("acl", "") @@ -889,7 +1089,22 @@ func DeleteObjectAcl(cli bce.Client, bucket, object string) error { // RETURNS: // - error: nil if success otherwise the specific error func RestoreObject(cli bce.Client, bucket string, object string, args ArchiveRestoreArgs) error { + return RestoreObjectWithContext(context.Background(), cli, bucket, object, args) +} + +// RestoreObjectWithContext - restore the archive object with context +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name +// - object: the object name +// - args: the restore args +// RETURNS: +// - error: nil if success otherwise the specific error +func RestoreObjectWithContext(ctx context.Context, cli bce.Client, bucket string, object string, args ArchiveRestoreArgs) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getObjectUri(bucket, object)) req.SetParam("restore", "") req.SetMethod(http.POST) @@ -918,7 +1133,23 @@ func RestoreObject(cli bce.Client, bucket string, object string, args ArchiveRes // RETURNS: // - error: nil if ok otherwise the specific error func PutObjectSymlink(cli bce.Client, bucket string, object string, symlinkKey string, symlinkArgs *PutSymlinkArgs) error { + return PutObjectSymlinkWithContext(context.Background(), cli, bucket, object, symlinkKey, symlinkArgs) +} + +// PutObjectSymlinkWithContext - put the object from the string or the stream with context +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name of the object +// - object: the name of the object +// - symlinkKey: the name of the symlink +// - symlinkArgs: the optional arguments of this api +// RETURNS: +// - error: nil if ok otherwise the specific error +func PutObjectSymlinkWithContext(ctx context.Context, cli bce.Client, bucket string, object string, symlinkKey string, symlinkArgs *PutSymlinkArgs) error { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getObjectUri(bucket, symlinkKey)) req.SetParam("symlink", "") req.SetMethod(http.PUT) @@ -959,7 +1190,7 @@ func PutObjectSymlink(cli bce.Client, bucket string, object string, symlinkKey s return nil } -// PutObjectSymlink - put the object from the string or the stream +// GetObjectSymlink - get the object symlink // // PARAMS: // - cli: the client agent which can perform sending request @@ -969,7 +1200,22 @@ func PutObjectSymlink(cli bce.Client, bucket string, object string, symlinkKey s // - string: the name of the target object // - error: nil if ok otherwise the specific error func GetObjectSymlink(cli bce.Client, bucket string, symlinkKey string) (string, error) { + return GetObjectSymlinkWithContext(context.Background(), cli, bucket, symlinkKey) +} + +// GetObjectSymlinkWithContext - get the object symlink with context +// +// PARAMS: +// - ctx: context to control the request +// - cli: the client agent which can perform sending request +// - bucket: the bucket name of the object +// - symlinkKey: the name of the symlink +// RETURNS: +// - string: the name of the target object +// - error: nil if ok otherwise the specific error +func GetObjectSymlinkWithContext(ctx context.Context, cli bce.Client, bucket string, symlinkKey string) (string, error) { req := &bce.BceRequest{} + req.SetContext(ctx) req.SetUri(getObjectUri(bucket, symlinkKey)) req.SetParam("symlink", "") req.SetMethod(http.GET) diff --git a/services/bos/client.go b/services/bos/client.go index a5ed5d96..fe91f67a 100644 --- a/services/bos/client.go +++ b/services/bos/client.go @@ -19,6 +19,7 @@ package bos import ( + "context" "encoding/json" "errors" "fmt" @@ -144,7 +145,18 @@ func NewClientWithConfig(config *BosClientConfiguration) (*Client, error) { // - *api.ListBucketsResult: the all buckets // - error: the return error if any occurs func (c *Client) ListBuckets() (*api.ListBucketsResult, error) { - return api.ListBuckets(c) + return c.ListBucketsWithContext(context.Background()) +} + +// ListBucketsWithContext - list all buckets with context +// +// PARAMS: +// - ctx: context to control the request +// RETURNS: +// - *api.ListBucketsResult: the all buckets +// - error: the return error if any occurs +func (c *Client) ListBucketsWithContext(ctx context.Context) (*api.ListBucketsResult, error) { + return api.ListBucketsWithContext(ctx, c) } // ListObjects - list all objects of the given bucket @@ -157,7 +169,21 @@ func (c *Client) ListBuckets() (*api.ListBucketsResult, error) { // - error: the return error if any occurs func (c *Client) ListObjects(bucket string, args *api.ListObjectsArgs) (*api.ListObjectsResult, error) { - return api.ListObjects(c, bucket, args) + return c.ListObjectsWithContext(context.Background(), bucket, args) +} + +// ListObjectsWithContext - list all objects of the given bucket with context +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the bucket name +// - args: the optional arguments to list objects +// RETURNS: +// - *api.ListObjectsResult: the all objects of the bucket +// - error: the return error if any occurs +func (c *Client) ListObjectsWithContext(ctx context.Context, bucket string, + args *api.ListObjectsArgs) (*api.ListObjectsResult, error) { + return api.ListObjectsWithContext(ctx, c, bucket, args) } // SimpleListObjects - list all objects of the given bucket with simple arguments @@ -172,9 +198,26 @@ func (c *Client) ListObjects(bucket string, // - *api.ListObjectsResult: the all objects of the bucket // - error: the return error if any occurs func (c *Client) SimpleListObjects(bucket, prefix string, maxKeys int, marker, + delimiter string) (*api.ListObjectsResult, error) { + return c.SimpleListObjectsWithContext(context.Background(), bucket, prefix, maxKeys, marker, delimiter) +} + +// SimpleListObjectsWithContext - list all objects of the given bucket with simple arguments and context +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the bucket name +// - prefix: the prefix for listing +// - maxKeys: the max number of result objects +// - marker: the marker to mark the beginning for the listing +// - delimiter: the delimiter for list objects +// RETURNS: +// - *api.ListObjectsResult: the all objects of the bucket +// - error: the return error if any occurs +func (c *Client) SimpleListObjectsWithContext(ctx context.Context, bucket, prefix string, maxKeys int, marker, delimiter string) (*api.ListObjectsResult, error) { args := &api.ListObjectsArgs{delimiter, marker, maxKeys, prefix} - return api.ListObjects(c, bucket, args) + return api.ListObjectsWithContext(ctx, c, bucket, args) } // HeadBucket - test the given bucket existed and access authority @@ -184,7 +227,18 @@ func (c *Client) SimpleListObjects(bucket, prefix string, maxKeys int, marker, // RETURNS: // - error: nil if exists and have authority otherwise the specific error func (c *Client) HeadBucket(bucket string) error { - err, _ := api.HeadBucket(c, bucket) + return c.HeadBucketWithContext(context.Background(), bucket) +} + +// HeadBucketWithContext - test the given bucket existed and access authority with context +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the bucket name +// RETURNS: +// - error: nil if exists and have authority otherwise the specific error +func (c *Client) HeadBucketWithContext(ctx context.Context, bucket string) error { + err, _ := api.HeadBucketWithContext(ctx, c, bucket) return err } @@ -196,7 +250,19 @@ func (c *Client) HeadBucket(bucket string) error { // - bool: true if exists and false if not exists or occurs error // - error: nil if exists or not exist, otherwise the specific error func (c *Client) DoesBucketExist(bucket string) (bool, error) { - err, _ := api.HeadBucket(c, bucket) + return c.DoesBucketExistWithContext(context.Background(), bucket) +} + +// DoesBucketExistWithContext - test the given bucket existed or not with context +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the bucket name +// RETURNS: +// - bool: true if exists and false if not exists or occurs error +// - error: nil if exists or not exist, otherwise the specific error +func (c *Client) DoesBucketExistWithContext(ctx context.Context, bucket string) (bool, error) { + err, _ := api.HeadBucketWithContext(ctx, c, bucket) if err == nil { return true, nil } @@ -211,9 +277,14 @@ func (c *Client) DoesBucketExist(bucket string) (bool, error) { return false, err } -//IsNsBucket - test the given bucket is namespace bucket or not +// IsNsBucket - test the given bucket is namespace bucket or not func (c *Client) IsNsBucket(bucket string) bool { - err, resp := api.HeadBucket(c, bucket) + return c.IsNsBucketWithContext(context.Background(), bucket) +} + +// IsNsBucketWithContext - test the given bucket is namespace bucket or not with context +func (c *Client) IsNsBucketWithContext(ctx context.Context, bucket string) bool { + err, resp := api.HeadBucketWithContext(ctx, c, bucket) if err == nil && resp.Header(sdk_http.BCE_BUCKET_TYPE) == api.NAMESPACE_BUCKET { return true } @@ -234,7 +305,19 @@ func (c *Client) IsNsBucket(bucket string) bool { // - string: the location of the new bucket if create success // - error: nil if create success otherwise the specific error func (c *Client) PutBucket(bucket string) (string, error) { - return api.PutBucket(c, bucket) + return c.PutBucketWithContext(context.Background(), bucket) +} + +// PutBucketWithContext - create a new bucket with context +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the new bucket name +// RETURNS: +// - string: the location of the new bucket if create success +// - error: nil if create success otherwise the specific error +func (c *Client) PutBucketWithContext(ctx context.Context, bucket string) (string, error) { + return api.PutBucketWithContext(ctx, c, bucket) } // DeleteBucket - delete a empty bucket @@ -244,7 +327,18 @@ func (c *Client) PutBucket(bucket string) (string, error) { // RETURNS: // - error: nil if delete success otherwise the specific error func (c *Client) DeleteBucket(bucket string) error { - return api.DeleteBucket(c, bucket) + return c.DeleteBucketWithContext(context.Background(), bucket) +} + +// DeleteBucketWithContext - delete a empty bucket with context +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the bucket name to be deleted +// RETURNS: +// - error: nil if delete success otherwise the specific error +func (c *Client) DeleteBucketWithContext(ctx context.Context, bucket string) error { + return api.DeleteBucketWithContext(ctx, c, bucket) } // GetBucketLocation - get the location fo the given bucket @@ -255,7 +349,19 @@ func (c *Client) DeleteBucket(bucket string) error { // - string: the location of the bucket // - error: nil if success otherwise the specific error func (c *Client) GetBucketLocation(bucket string) (string, error) { - return api.GetBucketLocation(c, bucket) + return c.GetBucketLocationWithContext(context.Background(), bucket) +} + +// GetBucketLocationWithContext - get the location fo the given bucket with context +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the bucket name +// RETURNS: +// - string: the location of the bucket +// - error: nil if success otherwise the specific error +func (c *Client) GetBucketLocationWithContext(ctx context.Context, bucket string) (string, error) { + return api.GetBucketLocationWithContext(ctx, c, bucket) } // PutBucketAcl - set the acl of the given bucket with acl body stream @@ -266,7 +372,19 @@ func (c *Client) GetBucketLocation(bucket string) (string, error) { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketAcl(bucket string, aclBody *bce.Body) error { - return api.PutBucketAcl(c, bucket, "", aclBody) + return c.PutBucketAclWithContext(context.Background(), bucket, aclBody) +} + +// PutBucketAclWithContext - set the acl of the given bucket with acl body stream and context +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the bucket name +// - aclBody: the acl json body stream +// RETURNS: +// - error: nil if success otherwise the specific error +func (c *Client) PutBucketAclWithContext(ctx context.Context, bucket string, aclBody *bce.Body) error { + return api.PutBucketAclWithContext(ctx, c, bucket, "", aclBody) } // PutBucketAclFromCanned - set the canned acl of the given bucket @@ -277,7 +395,19 @@ func (c *Client) PutBucketAcl(bucket string, aclBody *bce.Body) error { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketAclFromCanned(bucket, cannedAcl string) error { - return api.PutBucketAcl(c, bucket, cannedAcl, nil) + return c.PutBucketAclFromCannedWithContext(context.Background(), bucket, cannedAcl) +} + +// PutBucketAclFromCannedWithContext - set the canned acl of the given bucket with context +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the bucket name +// - cannedAcl: the cannedAcl string +// RETURNS: +// - error: nil if success otherwise the specific error +func (c *Client) PutBucketAclFromCannedWithContext(ctx context.Context, bucket, cannedAcl string) error { + return api.PutBucketAclWithContext(ctx, c, bucket, cannedAcl, nil) } // PutBucketAclFromFile - set the acl of the given bucket with acl json file name @@ -288,11 +418,23 @@ func (c *Client) PutBucketAclFromCanned(bucket, cannedAcl string) error { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketAclFromFile(bucket, aclFile string) error { + return c.PutBucketAclFromFileWithContext(context.Background(), bucket, aclFile) +} + +// PutBucketAclFromFileWithContext - set the acl of the given bucket with acl json file name and context +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the bucket name +// - aclFile: the acl file name +// RETURNS: +// - error: nil if success otherwise the specific error +func (c *Client) PutBucketAclFromFileWithContext(ctx context.Context, bucket, aclFile string) error { body, err := bce.NewBodyFromFile(aclFile) if err != nil { return err } - return api.PutBucketAcl(c, bucket, "", body) + return api.PutBucketAclWithContext(ctx, c, bucket, "", body) } // PutBucketAclFromString - set the acl of the given bucket with acl json string @@ -303,11 +445,23 @@ func (c *Client) PutBucketAclFromFile(bucket, aclFile string) error { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketAclFromString(bucket, aclString string) error { + return c.PutBucketAclFromStringWithContext(context.Background(), bucket, aclString) +} + +// PutBucketAclFromStringWithContext - set the acl of the given bucket with acl json string and context +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the bucket name +// - aclString: the acl string with json format +// RETURNS: +// - error: nil if success otherwise the specific error +func (c *Client) PutBucketAclFromStringWithContext(ctx context.Context, bucket, aclString string) error { body, err := bce.NewBodyFromString(aclString) if err != nil { return err } - return api.PutBucketAcl(c, bucket, "", body) + return api.PutBucketAclWithContext(ctx, c, bucket, "", body) } // PutBucketAclFromStruct - set the acl of the given bucket with acl data structure @@ -318,6 +472,18 @@ func (c *Client) PutBucketAclFromString(bucket, aclString string) error { // RETURNS: // - error: nil if success otherwise the specific error func (c *Client) PutBucketAclFromStruct(bucket string, aclObj *api.PutBucketAclArgs) error { + return c.PutBucketAclFromStructWithContext(context.Background(), bucket, aclObj) +} + +// PutBucketAclFromStructWithContext - set the acl of the given bucket with acl data structure and context +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the bucket name +// - aclObj: the acl struct object +// RETURNS: +// - error: nil if success otherwise the specific error +func (c *Client) PutBucketAclFromStructWithContext(ctx context.Context, bucket string, aclObj *api.PutBucketAclArgs) error { jsonBytes, jsonErr := json.Marshal(aclObj) if jsonErr != nil { return jsonErr @@ -326,7 +492,7 @@ func (c *Client) PutBucketAclFromStruct(bucket string, aclObj *api.PutBucketAclA if err != nil { return err } - return api.PutBucketAcl(c, bucket, "", body) + return api.PutBucketAclWithContext(ctx, c, bucket, "", body) } // GetBucketAcl - get the acl of the given bucket @@ -826,7 +992,23 @@ func (c *Client) DeleteBucketCopyrightProtection(bucket string) error { // - error: the uploaded error if any occurs func (c *Client) PutObject(bucket, object string, body *bce.Body, args *api.PutObjectArgs) (string, error) { - return api.PutObject(c, bucket, object, body, args) + return c.PutObjectWithContext(context.Background(), bucket, object, body, args) +} + +// PutObjectWithContext - upload a new object or rewrite the existed object with raw stream +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the name of the bucket to store the object +// - object: the name of the object +// - body: the object content body +// - args: the optional arguments +// RETURNS: +// - string: etag of the uploaded object +// - error: the uploaded error if any occurs +func (c *Client) PutObjectWithContext(ctx context.Context, bucket, object string, body *bce.Body, + args *api.PutObjectArgs) (string, error) { + return api.PutObjectWithContext(ctx, c, bucket, object, body, args) } // BasicPutObject - the basic interface of uploading an object @@ -839,7 +1021,21 @@ func (c *Client) PutObject(bucket, object string, body *bce.Body, // - string: etag of the uploaded object // - error: the uploaded error if any occurs func (c *Client) BasicPutObject(bucket, object string, body *bce.Body) (string, error) { - return api.PutObject(c, bucket, object, body, nil) + return c.BasicPutObjectWithContext(context.Background(), bucket, object, body) +} + +// BasicPutObjectWithContext - the basic interface of uploading an object +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the name of the bucket to store the object +// - object: the name of the object +// - body: the object content body +// RETURNS: +// - string: etag of the uploaded object +// - error: the uploaded error if any occurs +func (c *Client) BasicPutObjectWithContext(ctx context.Context, bucket, object string, body *bce.Body) (string, error) { + return c.PutObjectWithContext(ctx, bucket, object, body, nil) } // PutObjectFromBytes - upload a new object or rewrite the existed object from a byte array @@ -853,12 +1049,28 @@ func (c *Client) BasicPutObject(bucket, object string, body *bce.Body) (string, // - string: etag of the uploaded object // - error: the uploaded error if any occurs func (c *Client) PutObjectFromBytes(bucket, object string, bytesArr []byte, + args *api.PutObjectArgs) (string, error) { + return c.PutObjectFromBytesWithContext(context.Background(), bucket, object, bytesArr, args) +} + +// PutObjectFromBytesWithContext - upload a new object or rewrite the existed object from a byte array +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the name of the bucket to store the object +// - object: the name of the object +// - bytesArr: the content byte array +// - args: the optional arguments +// RETURNS: +// - string: etag of the uploaded object +// - error: the uploaded error if any occurs +func (c *Client) PutObjectFromBytesWithContext(ctx context.Context, bucket, object string, bytesArr []byte, args *api.PutObjectArgs) (string, error) { body, err := bce.NewBodyFromBytes(bytesArr) if err != nil { return "", err } - return api.PutObject(c, bucket, object, body, args) + return c.PutObjectWithContext(ctx, bucket, object, body, args) } // PutObjectFromString - upload a new object or rewrite the existed object from a string @@ -872,12 +1084,28 @@ func (c *Client) PutObjectFromBytes(bucket, object string, bytesArr []byte, // - string: etag of the uploaded object // - error: the uploaded error if any occurs func (c *Client) PutObjectFromString(bucket, object, content string, + args *api.PutObjectArgs) (string, error) { + return c.PutObjectFromStringWithContext(context.Background(), bucket, object, content, args) +} + +// PutObjectFromStringWithContext - upload a new object or rewrite the existed object from a string +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the name of the bucket to store the object +// - object: the name of the object +// - content: the content string +// - args: the optional arguments +// RETURNS: +// - string: etag of the uploaded object +// - error: the uploaded error if any occurs +func (c *Client) PutObjectFromStringWithContext(ctx context.Context, bucket, object, content string, args *api.PutObjectArgs) (string, error) { body, err := bce.NewBodyFromString(content) if err != nil { return "", err } - return api.PutObject(c, bucket, object, body, args) + return c.PutObjectWithContext(ctx, bucket, object, body, args) } // PutObjectFromFile - upload a new object or rewrite the existed object from a local file @@ -891,12 +1119,28 @@ func (c *Client) PutObjectFromString(bucket, object, content string, // - string: etag of the uploaded object // - error: the uploaded error if any occurs func (c *Client) PutObjectFromFile(bucket, object, fileName string, + args *api.PutObjectArgs) (string, error) { + return c.PutObjectFromFileWithContext(context.Background(), bucket, object, fileName, args) +} + +// PutObjectFromFileWithContext - upload a new object or rewrite the existed object from a local file +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the name of the bucket to store the object +// - object: the name of the object +// - fileName: the local file full path name +// - args: the optional arguments +// RETURNS: +// - string: etag of the uploaded object +// - error: the uploaded error if any occurs +func (c *Client) PutObjectFromFileWithContext(ctx context.Context, bucket, object, fileName string, args *api.PutObjectArgs) (string, error) { body, err := bce.NewBodyFromFile(fileName) if err != nil { return "", err } - return api.PutObject(c, bucket, object, body, args) + return c.PutObjectWithContext(ctx, bucket, object, body, args) } // PutObjectFromStream - upload a new object or rewrite the existed object from stream @@ -910,12 +1154,28 @@ func (c *Client) PutObjectFromFile(bucket, object, fileName string, // - string: etag of the uploaded object // - error: the uploaded error if any occurs func (c *Client) PutObjectFromStream(bucket, object string, reader io.Reader, + args *api.PutObjectArgs) (string, error) { + return c.PutObjectFromStreamWithContext(context.Background(), bucket, object, reader, args) +} + +// PutObjectFromStreamWithContext - upload a new object or rewrite the existed object from stream +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the name of the bucket to store the object +// - object: the name of the object +// - fileName: the local file full path name +// - args: the optional arguments +// RETURNS: +// - string: etag of the uploaded object +// - error: the uploaded error if any occurs +func (c *Client) PutObjectFromStreamWithContext(ctx context.Context, bucket, object string, reader io.Reader, args *api.PutObjectArgs) (string, error) { body, err := bce.NewBodyFromSizedReader(reader, -1) if err != nil { return "", err } - return api.PutObject(c, bucket, object, body, args) + return c.PutObjectWithContext(ctx, bucket, object, body, args) } // CopyObject - copy a remote object to another one @@ -1159,7 +1419,19 @@ func (c *Client) SimpleAppendObjectFromFile(bucket, object, filePath string, // RETURNS: // - error: any error if it occurs func (c *Client) DeleteObject(bucket, object string) error { - return api.DeleteObject(c, bucket, object) + return c.DeleteObjectWithContext(context.Background(), bucket, object) +} + +// DeleteObjectWithContext - delete the given object with context +// +// PARAMS: +// - ctx: context to control the request +// - bucket: the name of the bucket to delete +// - object: the name of the object to delete +// RETURNS: +// - error: any error if it occurs +func (c *Client) DeleteObjectWithContext(ctx context.Context, bucket, object string) error { + return api.DeleteObjectWithContext(ctx, c, bucket, object) } // DeleteMultipleObjects - delete a list of objects