summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorDr. Brandon Wiley <brandon@operatorfoundation.org>2019-08-23 18:19:08 -0500
committerDr. Brandon Wiley <brandon@operatorfoundation.org>2019-08-23 18:19:08 -0500
commitf468b19d78014e2cf5cc1d5f4bc2b4de5561c557 (patch)
tree3c421e0131e8e07bc05b4892eeff2c690d24a9ac /common
parentf1a5b02d7804a5616e2d8c80a110c06258dcf798 (diff)
Added a new way to parse transport options that allows for nested JSON
Diffstat (limited to 'common')
-rw-r--r--common/options.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/common/options.go b/common/options.go
new file mode 100644
index 0000000..9c73616
--- /dev/null
+++ b/common/options.go
@@ -0,0 +1,24 @@
+package options
+
+import (
+ "encoding/json"
+ "errors"
+ "fmt"
+ "strings"
+)
+
+func ParseOptions(s string) (map[string]interface{}, error) {
+ var result map[string]interface{}
+
+ if len(s) == 0 {
+ return nil, errors.New("Empty options")
+ }
+
+ decoder := json.NewDecoder(strings.NewReader(s))
+ if err := decoder.Decode(&result); err != nil {
+ fmt.Errorf("Error decoding JSON %q", err)
+ return nil, err
+ }
+
+ return result, nil
+}