blob
View on GitHubblob
Blob is a Go library that provides a unified interface for creating object storage buckets across multiple cloud providers. It parses a connection string URL, automatically determines the storage driver, and returns a ready-to-use objstore.Bucket backed by thanos-io/objstore.
Installation
go get github.com/corticph/gocomo/blob
Quick Start
1. Set the Connection String
The bucket is configured via the BLOB_STORAGE_CONNECTION_STRING environment variable.
S3:
s3://<access_key>:<secret_key>@<endpoint>/<bucket>?region=us-east-1
Azure:
azure://<client_id>:<client_secret>@<account_name>.blob.core.windows.net/<container>?az_tenant_id=<tenant-id>
Credentials are optional — if omitted, the provider falls back to its default credential chain (environment variables, config files, IAM, etc.).
2. Create a Bucket
import (
"log/slog"
"os"
"github.com/corticph/gocomo/blob"
)
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
bkt, err := blob.NewBucket(logger)
if err != nil {
log.Fatalf("Failed to create bucket: %v", err)
}
defer bkt.Close()
3. Upload and Download Objects
ctx := context.Background()
// Upload
if err := bkt.Upload(ctx, "my-object.txt", strings.NewReader("hello world")); err != nil {
log.Fatalf("Upload failed: %v", err)
}
// Download
rc, err := bkt.Get(ctx, "my-object.txt")
if err != nil {
log.Fatalf("Get failed: %v", err)
}
defer rc.Close()
data, _ := io.ReadAll(rc)
fmt.Println(string(data))
// Delete
if err := bkt.Delete(ctx, "my-object.txt"); err != nil {
log.Fatalf("Delete failed: %v", err)
}
Connection String Format
The connection string is a standard URL where the scheme selects the storage driver, the host and path provide driver-specific routing, and query parameters map to provider config fields.
S3
s3://[<access_key>:<secret_key>@]<endpoint>/<bucket>?key=value
| URL component | Config field | Description |
|---|---|---|
| host | endpoint |
S3 endpoint (e.g. s3.amazonaws.com) |
| path | bucket |
Bucket name |
| userinfo | access_key / secret_key |
Static credentials (optional) |
| query params | config fields | Any S3 provider field (dot notation for nested) |
When no userinfo is provided, the S3 provider falls back to the default credential chain (environment variables, ~/.aws/credentials, IAM).
Azure
azure://[<client_id>:<client_secret>@]<account_name>.blob.core.windows.net/<container>?key=value
| URL component | Config field | Description |
|---|---|---|
| host | storage_account / endpoint |
Derived from <account>.<endpoint> |
| path | container |
Container name |
| userinfo | client_id / client_secret |
Client secret auth (optional) |
| query params | config fields | Any Azure provider field (dot notation) |
Authentication priority:
storage_account_keyquery param — shared key authclient_id+client_secret(userinfo) +az_tenant_id(query param) — client secret auth- Neither —
DefaultAzureCredentialfrom the Azure identity SDK
For Azurite (local development), use storage_connection_string as a query param since the host has no subdomain:
azure://localhost:10000/devstoreaccount1/my-container?storage_connection_string=...
Query Parameters
Query parameters map directly to the underlying provider config fields. Nested fields use dot notation:
?http_config.insecure_skip_verify=true&http_config.max_idle_conns=250
Boolean values (true/false) and integers are automatically coerced. Strings with leading zeros are preserved as strings to avoid corrupting identifiers.
Supported Providers
| Provider | Driver | Tested with |
|---|---|---|
| S3 | s3 |
RustFS, AWS S3 |
| Azure | azure |
Azurite, Azure Storage |