aboutsummaryrefslogtreecommitdiff
path: root/connector/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'connector/config.go')
-rw-r--r--connector/config.go34
1 files changed, 29 insertions, 5 deletions
diff --git a/connector/config.go b/connector/config.go
index d719b49..e0fcf17 100644
--- a/connector/config.go
+++ b/connector/config.go
@@ -1,21 +1,45 @@
package connector
import (
+ "fmt"
"strconv"
+ "strings"
)
type Configuration map[string]string
-func (c Configuration) GetString(k string) string {
+func (c Configuration) GetString(k string, deflt ...string) (string, error) {
if ss, ok := c[k]; ok {
- return ss
+ return ss, nil
}
- return ""
+ if len(deflt) > 0 {
+ return deflt[0], nil
+ }
+ return "", fmt.Errorf("Missing configuration key: %s", k)
}
-func (c Configuration) GetInt(k string) (int, error) {
+func (c Configuration) GetInt(k string, deflt ...int) (int, error) {
if ss, ok := c[k]; ok {
return strconv.Atoi(ss)
}
- return 0, nil
+ if len(deflt) > 0 {
+ return deflt[0], nil
+ }
+ return 0, fmt.Errorf("Missing configuration key: %s", k)
+}
+
+func (c Configuration) GetBool(k string, deflt ...bool) (bool, error) {
+ if ss, ok := c[k]; ok {
+ if strings.EqualFold(ss, "true") {
+ return true, nil
+ } else if strings.EqualFold(ss, "false") {
+ return false, nil
+ } else {
+ return false, fmt.Errorf("Invalid value: %s", ss)
+ }
+ }
+ if len(deflt) > 0 {
+ return deflt[0], nil
+ }
+ return false, fmt.Errorf("Missing configuration key: %s", k)
}