summaryrefslogtreecommitdiff
path: root/common/options.go
diff options
context:
space:
mode:
Diffstat (limited to 'common/options.go')
-rw-r--r--common/options.go39
1 files changed, 36 insertions, 3 deletions
diff --git a/common/options.go b/common/options.go
index 9c73616..f0ededf 100644
--- a/common/options.go
+++ b/common/options.go
@@ -3,7 +3,8 @@ package options
import (
"encoding/json"
"errors"
- "fmt"
+ "github.com/OperatorFoundation/shapeshifter-dispatcher/common/log"
+ interconv "github.com/mufti1/interconv/package"
"strings"
)
@@ -11,14 +12,46 @@ func ParseOptions(s string) (map[string]interface{}, error) {
var result map[string]interface{}
if len(s) == 0 {
- return nil, errors.New("Empty options")
+ return map[string]interface{}{}, nil
}
decoder := json.NewDecoder(strings.NewReader(s))
if err := decoder.Decode(&result); err != nil {
- fmt.Errorf("Error decoding JSON %q", err)
+ log.Errorf("Error decoding JSON %q", err)
return nil, err
}
return result, nil
}
+
+func ParseServerOptions(s string) (params map[string]map[string]interface{}, err error) {
+ result := make(map[string]map[string]interface{})
+
+ if len(s) == 0 {
+ return result, nil
+ }
+
+ decoder := json.NewDecoder(strings.NewReader(s))
+ if err := decoder.Decode(&result); err != nil {
+ log.Errorf("Error decoding JSON %q", err)
+ return nil, err
+ }
+
+ return result, nil
+}
+
+func CoerceToString(futureString interface{}) (*string, error) {
+ var result string
+
+ switch futureString.(type) {
+ case string:
+ var icerr error
+ result, icerr = interconv.ParseString(futureString)
+ if icerr != nil {
+ return nil, icerr
+ }
+ return &result, nil
+ default:
+ return nil, errors.New("unable to coerce empty interface to string")
+ }
+} \ No newline at end of file