diff options
| author | Jeff Carr <[email protected]> | 2024-12-19 10:31:42 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-12-19 10:31:42 -0600 |
| commit | 8f9b66f6c8565f08e18098e330dfe73c22592b9f (patch) | |
| tree | 672c89ed98e4f08a04f35329d1b4779dadeb6575 /blobby/main.go | |
| parent | c5fb46c60d4a0383e0e3586bd2d4968e8a8907b7 (diff) | |
blobby
Diffstat (limited to 'blobby/main.go')
| -rw-r--r-- | blobby/main.go | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/blobby/main.go b/blobby/main.go new file mode 100644 index 0000000..5b6f89f --- /dev/null +++ b/blobby/main.go @@ -0,0 +1,55 @@ +package main + +import ( + "gocloud.dev/blob" + // _ "gocloud.dev/blob/<driver>" + "context" + "fmt" + + _ "gocloud.dev/blob/mysql" +) + +func main() { + bucket, err := blob.OpenBucket(context.Background(), "<driver-url>") + if err != nil { + return fmt.Errorf("could not open bucket: %v", err) + } + defer bucket.Close() + // bucket is a *blob.Bucket; see usage below + + // You can wrap a *blob.Bucket to always operate on a subfolder of the bucket using blob.PrefixedBucket: + + // import "gocloud.dev/blob" + + // Wrap the bucket using blob.PrefixedBucket. + // The prefix should end with "/", so that the resulting bucket operates + // in a subfolder. + bucket = blob.PrefixedBucket(bucket, "a/subfolder/") + + // The original bucket is no longer usable; it has been closed. + // The wrapped bucket should be closed when done. + defer bucket.Close() + + // Bucket operations on <key> will be translated to "a/subfolder/<key>". + + // Alternatively, you can configure the prefix directly in the blob.OpenBucket URL: + + /* + import ( + "context" + "gocloud.dev/blob" + ) + */ + + // Connect to a bucket using a URL, using the "prefix" query parameter to + // target a subfolder in the bucket. + // The prefix should end with "/", so that the resulting bucket operates + // in a subfolder. + b, err := blob.OpenBucket(ctx, "mem://?prefix=a/subfolder/") + if err != nil { + return err + } + defer b.Close() + + // Bucket operations on <key> will be translated to "a/subfolder/<key>". +} |
