From 770bc14548a6a48ccbc8be0f0583122cf1dc6f6e Mon Sep 17 00:00:00 2001 From: Bluesaxorcist Date: Mon, 21 Oct 2019 15:16:49 -0500 Subject: added dialer to the modes and removed unneccessary code --- common/options.go | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'common/options.go') 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 -- cgit v1.2.3