From f468b19d78014e2cf5cc1d5f4bc2b4de5561c557 Mon Sep 17 00:00:00 2001 From: "Dr. Brandon Wiley" Date: Fri, 23 Aug 2019 18:19:08 -0500 Subject: Added a new way to parse transport options that allows for nested JSON --- common/options.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 common/options.go (limited to 'common') 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 +} -- cgit v1.2.3