package driver import ( "net/url" "forge.cadoles.com/arcad/edge/pkg/storage" "github.com/pkg/errors" ) var blobStoreFactories = make(map[string]BlobStoreFactory, 0) type BlobStoreFactory func(url *url.URL) (storage.BlobStore, error) func RegisterBlobStoreFactory(scheme string, factory BlobStoreFactory) { blobStoreFactories[scheme] = factory } func NewBlobStore(dsn string) (storage.BlobStore, error) { url, err := url.Parse(dsn) if err != nil { return nil, errors.WithStack(err) } factory, exists := blobStoreFactories[url.Scheme] if !exists { return nil, errors.Wrapf(ErrSchemeNotRegistered, "no driver associated with scheme '%s'", url.Scheme) } store, err := factory(url) if err != nil { return nil, errors.WithStack(err) } return store, nil }