BackGo/pkg/backup/s3.go

55 lines
1.4 KiB
Go

package backup
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
)
// S3Client wraps the AWS S3 client
type S3Client struct {
Client *s3.Client
Bucket string
}
// NewS3Client initializes and returns a new S3 client
func NewS3Client(bucket string) (*S3Client, error) {
cfg, err := config.LoadDefaultConfig(context.TODO(),
config.WithRegion("us-west-2"), // Specify your region
)
if err != nil {
return nil, fmt.Errorf("unable to load SDK config, %w", err)
}
s3Client := s3.NewFromConfig(cfg)
return &S3Client{
Client: s3Client,
Bucket: bucket,
}, nil
}
// UploadFile uploads a file to the specified S3 bucket
func (c *S3Client) UploadFile(key string, filePath string) error {
// Implementation for uploading file to S3
// need to open the file and use PutObject API call
return nil
}
// DeleteFile deletes a file from the specified S3 bucket
func (c *S3Client) DeleteFile(key string) error {
// Implementation for deleting file from S3 using DeleteObject API call
return nil
}
// ListFiles lists all files (backups) in the specified S3 bucket
func (c *S3Client) ListFiles() ([]string, error) {
// Implementation for listing files in S3 bucket using ListObjectsV2 API call
return nil, nil
}
// SetBucket sets the S3 bucket for the client
func (c *S3Client) SetBucket(bucket string) {
c.Bucket = bucket
}