Documentation
¶
Overview ¶
Package s3 provides utilities for working with AWS S3 (Simple Storage Service).
This package wraps the AWS SDK v2 S3 client to provide simplified functions for bucket and object management operations.
Features:
- Bucket operations (create, list, delete)
- Object operations (put, get, delete)
- Custom endpoint support (for S3-compatible services)
- Path-style and virtual-hosted-style access
Example usage:
var client s3.Client
err := client.CreateClient(ctx, "us-east-1", "key", "secret", "")
_, err = client.PutObject("bucket", "key", "data")
Index ¶
- type Client
- func (c *Client) CreateBucket(name, region string) (*aws_s3.CreateBucketOutput, error)
- func (c *Client) CreateClient(ctx context.Context, region, accessKey, secretAccessKey, sessionToken string, ...) error
- func (c *Client) DeleteBucket(name string) (*aws_s3.DeleteBucketOutput, error)
- func (c *Client) DeleteObject(bucketName string, key string) (*aws_s3.DeleteObjectOutput, error)
- func (c *Client) GetObject(bucketName string, key string) (*aws_s3.GetObjectOutput, error)
- func (c *Client) ListBuckets() (*aws_s3.ListBucketsOutput, error)
- func (c *Client) PutObject(bucketName, key, body string) (*aws_s3.PutObjectOutput, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a struct that provides client related methods.
func (*Client) CreateBucket ¶
func (c *Client) CreateBucket(name, region string) (*aws_s3.CreateBucketOutput, error)
CreateBucket creates a new S3 bucket.
Parameters:
- name: bucket name (must be globally unique)
- region: AWS region for the bucket (empty string for default region)
Returns the CreateBucketOutput and any error encountered.
Example:
_, err := client.CreateBucket("my-bucket", "us-west-2")
func (*Client) CreateClient ¶
func (c *Client) CreateClient(ctx context.Context, region, accessKey, secretAccessKey, sessionToken string, s3OptionsFuncs ...func(*aws_s3.Options)) error
CreateClient creates an S3 client with service-specific options.
This is the recommended way to create an S3 client with custom endpoint and other service-specific configurations (e.g., for MinIO or LocalStack).
Parameters:
- ctx: context for the client lifecycle
- region: AWS region (e.g., "us-east-1")
- accessKey: AWS access key ID
- secretAccessKey: AWS secret access key
- sessionToken: optional session token (empty string if not using temporary credentials)
- s3OptionsFuncs: optional service-specific configuration functions
Example:
err := client.CreateClient(context.TODO(), "us-east-1", "access-key", "secret-key", "",
func(o *s3.Options) {
o.BaseEndpoint = aws.String("http://localhost:9000")
o.UsePathStyle = true
})
func (*Client) DeleteBucket ¶
func (c *Client) DeleteBucket(name string) (*aws_s3.DeleteBucketOutput, error)
DeleteBucket deletes an S3 bucket.
The bucket must be empty before it can be deleted.
Parameters:
- name: bucket name to delete
Returns the DeleteBucketOutput and any error encountered.
Example:
_, err := client.DeleteBucket("my-bucket")
func (*Client) DeleteObject ¶
DeleteObject deletes an object from the specified bucket.
Parameters:
- bucketName: name of the bucket
- key: object key (path) to delete
Returns the DeleteObjectOutput and any error encountered.
Example:
_, err := client.DeleteObject("my-bucket", "docs/file.txt")
func (*Client) GetObject ¶
GetObject retrieves an object from the specified bucket.
Parameters:
- bucketName: name of the bucket
- key: object key (path) in the bucket
Returns the GetObjectOutput containing the object data and any error encountered.
Example:
output, err := client.GetObject("my-bucket", "docs/file.txt")
func (*Client) ListBuckets ¶
func (c *Client) ListBuckets() (*aws_s3.ListBucketsOutput, error)
ListBuckets retrieves all buckets owned by the authenticated sender.
Returns the ListBucketsOutput containing all buckets and any error encountered.
Example:
output, err := client.ListBuckets()
func (*Client) PutObject ¶
func (c *Client) PutObject(bucketName, key, body string) (*aws_s3.PutObjectOutput, error)
PutObject uploads an object to the specified bucket.
Parameters:
- bucketName: name of the bucket
- key: object key (path) in the bucket
- body: object content as string
Returns the PutObjectOutput and any error encountered.
Example:
_, err := client.PutObject("my-bucket", "docs/file.txt", "Hello, World!")