aboutsummaryrefslogtreecommitdiff
path: root/storage/registry
diff options
context:
space:
mode:
Diffstat (limited to 'storage/registry')
-rw-r--r--storage/registry/filter_conf.go39
-rw-r--r--storage/registry/registry.go13
2 files changed, 47 insertions, 5 deletions
diff --git a/storage/registry/filter_conf.go b/storage/registry/filter_conf.go
new file mode 100644
index 0000000..593f238
--- /dev/null
+++ b/storage/registry/filter_conf.go
@@ -0,0 +1,39 @@
+package registry
+
+import (
+ "code.laria.me/petrific/config"
+ "code.laria.me/petrific/storage"
+ "code.laria.me/petrific/storage/filter"
+)
+
+// Unlike the other storage engines, we can not define FilterStorages
+// *FromConfig function in the package itself, because we need to reference the
+// registry package and circular imports are not allowed
+
+func filterStorageFromConfig(conf config.Config, name string) (storage.Storage, error) {
+ var storage_conf struct {
+ Base string
+ Encode []string
+ Decode []string
+ }
+
+ if err := conf.GetStorageConfData(name, &storage_conf); err != nil {
+ return nil, err
+ }
+
+ base, err := LoadStorage(conf, storage_conf.Base)
+ if err != nil {
+ return nil, err
+ }
+
+ st := filter.FilterStorage{Base: base}
+
+ if len(storage_conf.Encode) > 0 {
+ st.Encode = filter.PipeFilter(storage_conf.Encode)
+ }
+ if len(storage_conf.Decode) > 0 {
+ st.Decode = filter.PipeFilter(storage_conf.Decode)
+ }
+
+ return st, nil
+}
diff --git a/storage/registry/registry.go b/storage/registry/registry.go
index f792946..4b48ef4 100644
--- a/storage/registry/registry.go
+++ b/storage/registry/registry.go
@@ -11,10 +11,13 @@ import (
)
// List af all available storage types
-var StorageTypes = map[string]storage.CreateStorageFromConfig{
- "local": local.LocalStorageFromConfig,
- "memory": memory.MemoryStorageFromConfig,
- "openstack-swift": cloud.SwiftStorageCreator(),
+func getStorageTypes() map[string]storage.CreateStorageFromConfig {
+ return map[string]storage.CreateStorageFromConfig{
+ "local": local.LocalStorageFromConfig,
+ "memory": memory.MemoryStorageFromConfig,
+ "filter": filterStorageFromConfig,
+ "openstack-swift": cloud.SwiftStorageCreator(),
+ }
}
var notFoundErr = errors.New("Storage not found")
@@ -41,7 +44,7 @@ func loadStorage(conf config.Config, storageName string) (storage.Storage, error
return nil, err
}
- st, ok := StorageTypes[method]
+ st, ok := getStorageTypes()[method]
if !ok {
return nil, unknownMethodErr(method)
}