summaryrefslogtreecommitdiff
path: root/common/options.go
blob: 9c7361654db14120b63a95236e7a6efdcc37955f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
}