forked from influxdata/influxdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry.go
48 lines (40 loc) · 1.24 KB
/
registry.go
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
40
41
42
43
44
45
46
47
48
package storage
import (
"fmt"
"strings"
)
var engineRegistry = make(map[string]Initializer)
type Initializer struct {
NewConfig func() interface{}
Initialize func(path string, config interface{}) (Engine, error)
}
func wrapInitializer(initializer Initializer) Initializer {
var init Initializer
init.Initialize = func(path string, config interface{}) (Engine, error) {
engine, err := initializer.Initialize(path, config)
if err != nil {
return nil, err
}
// these sentinel values are here so that we can seek to the end of
// the keyspace and have the iterator still be valid. this is for
// the series that is at either end of the keyspace.
engine.Put([]byte(strings.Repeat("\x00", 24)), []byte{})
engine.Put([]byte(strings.Repeat("\xff", 24)), []byte{})
return engine, nil
}
init.NewConfig = initializer.NewConfig
return init
}
func registerEngine(name string, init Initializer) {
if _, ok := engineRegistry[name]; ok {
panic(fmt.Errorf("Engine '%s' already exists", name))
}
engineRegistry[name] = wrapInitializer(init)
}
func GetInitializer(name string) (Initializer, error) {
initializer, ok := engineRegistry[name]
if !ok {
return initializer, fmt.Errorf("Engine '%s' not found", name)
}
return initializer, nil
}