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

.

parent 9f0738e5
......@@ -28,9 +28,9 @@ import (
func openByURL(u *url.URL) (zodb.IStorage, error) {
// TODO handle query
// XXX u.Path is not always raw path - recheck and fix
return Open(u.Path)
return Open(u.Host + u.Path)
}
func init() {
zodb.RegisterStorage("file://", openByURL)
zodb.RegisterStorage("file", openByURL)
}
......@@ -19,10 +19,25 @@ package zodb
// logic to open storages by URL
import (
"fmt"
"net/url"
"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
// Only URL schemes registered to zodb package are handled.
......@@ -37,14 +52,15 @@ func OpenStorageURL(storageURL string) (IStorage, error) {
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
type StorageOpener func (u *url.URL) (IStorage, error)
opener, ok := storageRegistry[u.Scheme]
if !ok {
return nil, fmt.Errorf("zodb: URL scheme \"%s://\" not supported", u.Scheme)
}
// RegisterStorage registers handler to be used for URLs with scheme
func RegisterStorage(scheme string, handler StorageOpener) {
// TODO
return opener(u)
}
......@@ -16,7 +16,7 @@
// See COPYING file for full licensing terms.
// 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
//
......
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