-
Notifications
You must be signed in to change notification settings - Fork 0
/
configurationEnabler.go
38 lines (33 loc) · 1.04 KB
/
configurationEnabler.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
package libreConfig
import (
"errors"
"github.com/Spruik/libre-configuration/shared"
)
const errMessageNotInitalized = "configurationEnabler not initialized. Please call `Initialize(\"path/to/file.json\")`"
type ConfigurationEnabler struct {
category string
}
func (s *ConfigurationEnabler) SetConfigCategory(cat string) {
if s == nil {
panic("cannot set category of uninitialized")
}
s.category = cat
}
func (s *ConfigurationEnabler) GetConfigItem(key string) (string, error) {
if cfgSvc == nil {
return "", errors.New(errMessageNotInitalized)
}
return cfgSvc.GetConfigEntry(s.category, key)
}
func (s *ConfigurationEnabler) GetConfigItemWithDefault(key string, dflt string) (string, error) {
if cfgSvc == nil {
return dflt, errors.New(errMessageNotInitalized)
}
return cfgSvc.GetConfigEntryWithDefault(s.category, key, dflt)
}
func (s *ConfigurationEnabler) GetConfigStanza(key string) (*shared.ConfigItem, error) {
if cfgSvc == nil {
return nil, errors.New(errMessageNotInitalized)
}
return cfgSvc.GetConfigStanza(s.category, key)
}