blob: 593f238a5fe16f5cc2f4c01718f5bf38963a384a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
}
|