This topic describes how to delete a single object or multiple objects using OSS SDK for Go.
Notes
The sample code in this topic uses the
cn-hangzhouregion ID, which corresponds to the China (Hangzhou) region. By default, a public endpoint is used to access resources in a bucket. If you access the bucket from other Alibaba Cloud services in the same region, use an internal endpoint. For more information about the regions and endpoints available for Object Storage Service (OSS), see OSS regions and endpoints.In this topic, access credentials are obtained from environment variables. For more information about how to configure access credentials, see Configure access credentials.
To delete objects, you must have the
oss:DeleteObjectpermission. For more information, see Grant custom permissions to RAM users.
Methods
Delete a single object
func (c *Client) DeleteObject(ctx context.Context, request *DeleteObjectRequest, optFns ...func(*Options)) (*DeleteObjectResult, error)Delete multiple objects
func (c *Client) DeleteMultipleObjects(ctx context.Context, request *DeleteMultipleObjectsRequest, optFns ...func(*Options)) (*DeleteMultipleObjectsResult, error)Request parameters
Parameter | Type | Description |
ctx | context.Context | The context of the request, which can be used to specify the total duration of the request. |
request | *DeleteObjectRequest | Parameters of an API operation, such as the name of the object. For more information, visit DeleteObjectRequest. |
*DeleteMultipleObjectsRequest | Parameters of an API operation, such as the list of objects to delete. For more information, visit DeleteMultipleObjectsRequest. | |
optFns | ...func(*Options) | Optional. The operation-level parameters. For more information, see Options. |
Response parameters
Return parameter | Type | Description |
result | *DeleteObjectResult | The response to the operation. This parameter is valid when the value of err is nil. For more information, visit DeleteObjectResult. |
*GetObjectResult | The response to the operation. This parameter is valid when the value of err is nil. For more information, visit DeleteMultipleObjectsResult. | |
err | error | The status of the request. If the request fails, the value of err is not nil. |
Sample code
References
For more information about the complete sample code that is used to delete objects, visit delete_object.go and delete_mutiple_objects.go.
For more information about the API operation that you can call to delete a single object, see DeleteObject.
For more information about the API operation that you can call to delete multiple objects, see DeleteMultipleObjects.