Commit 954321b2 authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb: Provide OpenDriver in addition to Open

This is low-level API to open IStorageDriver instead of IStorage.
Demo storage will need this.

Maybe it would be a good idea to move drivers-related functionality into
separate package in the future.
parent 5aa4372f
......@@ -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
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment