Commit 38482c68 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 9f0738e5
...@@ -28,9 +28,9 @@ import ( ...@@ -28,9 +28,9 @@ import (
func openByURL(u *url.URL) (zodb.IStorage, error) { func openByURL(u *url.URL) (zodb.IStorage, error) {
// TODO handle query // TODO handle query
// XXX u.Path is not always raw path - recheck and fix // XXX u.Path is not always raw path - recheck and fix
return Open(u.Path) return Open(u.Host + u.Path)
} }
func init() { func init() {
zodb.RegisterStorage("file://", openByURL) zodb.RegisterStorage("file", openByURL)
} }
...@@ -19,10 +19,25 @@ package zodb ...@@ -19,10 +19,25 @@ package zodb
// logic to open storages by URL // logic to open storages by URL
import ( import (
"fmt"
"net/url" "net/url"
"strings" "strings"
) )
// StorageOpener is a function to open a storage
type StorageOpener func (u *url.URL) (IStorage, error)
// {} scheme -> StorageOpener
var storageRegistry = map[string]StorageOpener{}
// RegisterStorage registers opener to be used for URLs with scheme
func RegisterStorage(scheme string, opener StorageOpener) {
if _, already := storageRegistry[scheme]; already {
panic(fmt.Errorf("ZODB URL scheme %q was already registered", scheme))
}
storageRegistry[scheme] = opener
}
// OpenStorage opens ZODB storage by URL // OpenStorage opens ZODB storage by URL
// Only URL schemes registered to zodb package are handled. // Only URL schemes registered to zodb package are handled.
...@@ -37,14 +52,15 @@ func OpenStorageURL(storageURL string) (IStorage, error) { ...@@ -37,14 +52,15 @@ func OpenStorageURL(storageURL string) (IStorage, error) {
storageURL = "file://" + storageURL storageURL = "file://" + storageURL
} }
return nil, nil u, err := url.Parse(storageURL)
} if err != nil {
return nil, err
}
// StorageOpener is a function to open a storage opener, ok := storageRegistry[u.Scheme]
type StorageOpener func (u *url.URL) (IStorage, error) if !ok {
return nil, fmt.Errorf("zodb: URL scheme \"%s://\" not supported", u.Scheme)
}
// RegisterStorage registers handler to be used for URLs with scheme return opener(u)
func RegisterStorage(scheme string, handler StorageOpener) {
// TODO
} }
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
// See COPYING file for full licensing terms. // See COPYING file for full licensing terms.
// Package wks links-in well-known ZODB storages // Package wks links-in well-known ZODB storages
// The only purpose of this package is so that users import it // The only purpose of this package is so that users could import it
// //
// import _ ".../zodb/wks" XXX fixme import path // import _ ".../zodb/wks" XXX fixme import path
// //
......
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