aboutsummaryrefslogtreecommitdiff
path: root/storage/registry/filter_conf.go
blob: 7cc113e28d8cfb89f91eb5deba3a98fa97c43d92 (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 (
	"github.com/silvasur/petrific/config"
	"github.com/silvasur/petrific/storage"
	"github.com/silvasur/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
}