-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig_store.go
More file actions
38 lines (31 loc) · 992 Bytes
/
config_store.go
File metadata and controls
38 lines (31 loc) · 992 Bytes
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
package fastlike
// addConfigStore registers a named config store with the given lookup function.
func (i *Instance) addConfigStore(name string, fn LookupFunc) {
if i.configStores == nil {
i.configStores = []configStore{}
}
i.configStores = append(i.configStores, configStore{name, fn})
}
// getConfigStoreHandle retrieves the handle for a named config store.
// Returns HandleInvalid if the config store is not found.
func (i *Instance) getConfigStoreHandle(name string) int {
for j, cs := range i.configStores {
if cs.name == name {
return j
}
}
return HandleInvalid
}
// getConfigStore retrieves a config store's lookup function by handle.
// Returns nil if the handle is invalid.
func (i *Instance) getConfigStore(handle int) LookupFunc {
if handle < 0 || handle > len(i.configStores)-1 {
return nil
}
return i.configStores[handle].get
}
// configStore represents a named configuration key-value store.
type configStore struct {
name string
get LookupFunc
}