diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/options.go | 24 |
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 +} |