Skip to content

Latest commit

 

History

History
60 lines (48 loc) · 2.08 KB

File metadata and controls

60 lines (48 loc) · 2.08 KB

Storage (removed)

This extension is gone. Use trove instead.

Trove covers everything this did and a good deal more. Same local, S3, GCS and Azure backends, plus SFTP, streaming transfers you can pause and resume, content-addressable storage with deduplication, and an io/fs.FS view over flat object storage. It ships its own Forge extension, so swapping is mostly a matter of changing what you register.

Moving over

go get github.com/xraph/trove

Where you registered this extension:

storage.NewExtensionWithConfig(storage.Config{
    Backends: map[string]storage.BackendConfig{
        "default": {
            Type:   "local",
            Config: map[string]interface{}{"base_path": "./data"},
        },
    },
    Default: "default",
})

register trove's:

import (
    troveext "github.com/xraph/trove/extension"
    _ "github.com/xraph/trove/drivers/localdriver"
)

troveext.New(
    troveext.WithFileStoreDSN("default", "local://./data"),
    troveext.WithDefaultFileStore("default"),
)

Backends are DSNs now instead of a type plus a config map. local://./relative, file:///var/data, s3://us-east-1/my-bucket and gcs://my-bucket all work. Import the driver you need for its side effects, the way you would a database driver. Miss that and the scheme will not resolve.

Then inject *trove.Trove where you used to inject storage.Storage. Buckets are the one real change at the call site: every object lives in one, so Upload(ctx, key, r) becomes Put(ctx, bucket, key, r) and the rest follow the same shape. Create the bucket once at startup with CreateBucket, because trove will not write into a bucket that does not exist yet, and a first write that fails on a missing bucket is a confusing way to find that out.

If you want a worked example, the hls extension made this exact move. Its storage package declares a six-method interface of its own and implements that over trove. Copy the idea. It keeps a vendor's API out of your call sites, which is what made this migration a new file rather than a rewrite.