diff --git a/go/zodb/storage.go b/go/zodb/storage.go index 719d53d555d5e4f828704d8a86cb048fa72a5215..9c5126c02ada88e7e7ea9283b674d10754aa36c1 100644 --- a/go/zodb/storage.go +++ b/go/zodb/storage.go @@ -91,14 +91,11 @@ func RegisterDriver(scheme string, opener DriverOpener) { driverRegistry[scheme] = opener } -// Open opens ZODB storage by URL. -// -// Only URL schemes registered to zodb package are handled. -// Users should import in storage packages they use or zodb/wks package to -// get support for well-known storages. +// OpenDriver opens ZODB storage driver by URL. // -// Storage authors should register their storages with RegisterStorage. -func Open(ctx context.Context, zurl string, opt *OpenOptions) (IStorage, error) { +// It is similar to Open but returns low-level IStorageDriver instead of IStorage. +// Most users should use Open. +func OpenDriver(ctx context.Context, zurl string, opt *DriverOptions) (_ IStorageDriver, at0 Tid, _ error) { // no scheme -> file:// if !strings.Contains(zurl, ":") { zurl = "file://" + zurl @@ -106,7 +103,7 @@ func Open(ctx context.Context, zurl string, opt *OpenOptions) (IStorage, error) u, err := url.Parse(zurl) if err != nil { - return nil, err + return nil, InvalidTid, err } // XXX commonly handle some options from url -> opt? @@ -115,16 +112,32 @@ func Open(ctx context.Context, zurl string, opt *OpenOptions) (IStorage, error) opener, ok := driverRegistry[u.Scheme] if !ok { - return nil, fmt.Errorf("zodb: URL scheme \"%s:\" not supported", u.Scheme) + return nil, InvalidTid, fmt.Errorf("zodb: URL scheme \"%s:\" not supported", u.Scheme) + } + + storDriver, at0, err := opener(ctx, u, opt) + if err != nil { + return nil, InvalidTid, err } + return storDriver, at0, nil +} + +// Open opens ZODB storage by URL. +// +// Only URL schemes registered to zodb package are handled. +// Users should import in storage packages they use or zodb/wks package to +// get support for well-known storages. +// +// Storage authors should register their storages with RegisterDriver. +func Open(ctx context.Context, zurl string, opt *OpenOptions) (IStorage, error) { drvWatchq := make(chan Event) drvOpt := &DriverOptions{ ReadOnly: opt.ReadOnly, Watchq: drvWatchq, } - storDriver, at0, err := opener(ctx, u, drvOpt) + storDriver, at0, err := OpenDriver(ctx, zurl, drvOpt) if err != nil { return nil, err }