A wrapper module usable for communicating with a S3 compatible object storage via HTTP. Http client for request execution can be configured manually so that it could be used in a e.g. WebAssembly context.
Prototype WASI-HTTP Interface: https://github.com/ydnar/wasi-http-go
- Add the module to your
go.mod
require github.com/cedweber/go-s3-wrapper
- Use the module within your logic
s3 "github.com/cedweber/go-s3-wrapper"
- Use the module
cfg := s3.Config{
Endpoint: baseDomain,
AccessKey: accessKey,
SecretKey: secretKey,
Region: region,
}
// Create a New S3 client.
s3Client, err := s3.New(cfg)
if err != nil {
fmt.Printf("failed to create source client %v\n", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
Use the client to interact via REST with S3, e.g.
bucketName := "my-bucket"
filePath := "my-file"
ctx := context.Background()
// Get http response from HEAD request
resp, err := s3Client.HeadObject(ctx, bucketName, filePath)
if err != nil {
fmt.Printf("failed to get file info %\n", err)
}
The following operations are supported:
- CreateBucket
- ListBuckets
- ListObjects
- ListObjectsV2
- ListObjectVersions
- HeadObject
- GetObject
- GetObjectPart
- PutObject
- PutObjectStream
- DeleteObject
- DeleteObjects
- CreateMultipartUpload
- UploadPart
- CompleteMultipartUpload
- ListMultipartUploads
- AbortMultipartUpload
- ListParts
- GetObjectTagging
- PutObjectTagging
- DeleteObjectTagging
- GetObjectAttributes
- ListDirectoryBuckets
- GetBucketWebsite
- PutBucketWebsite
- DeleteBucketWebsite
- GetBucketVersioning
- PutBucketVersioning
- GetBucketTagging
- PutBucketTagging
- DeleteBucketTagging
- PutObjectLockConfiguration
- GetObjectLockConfiguration
- GetObjectRetention
- PutObjectRetention
- GetObjectAcl
- PutObjectAcl
- GetBucketAcl
- PutBucketAcl
- GetBucketLogging
- PutBucketLogging
- GetPublicAccessBlock
- PutPublicAccessBlock
- DeletePublicAccessBlock
- GetBucketNotificationConfiguration
- PutBucketNotificationConfiguration
- GetBucketMetricsConfiguration
- ListBucketMetricsConfigurations
- PutBucketMetricsConfiguration
- DeleteBucketMetricsConfiguration
- GetObjectLegalHold
- PutObjectLegalHold
- GetBucketPolicyStatus
- GetBucketPolicy
- PutBucketPolicy
- DeleteBucketPolicy
- GetBucketLifecycleConfiguration
- PutBucketLifecycleConfiguration
- DeleteBucketLifecycle
- GetBucketMetadataTableConfiguration
- CreateBucketMetadataTableConfiguration
- DeleteBucketMetadataTableConfiguration
If you think something is missing or wrong feel free to contribute.
Thanks and credits to Fermyon for the support and the initial code base