review feedback

* Opted to remove json path traversal, as it added more code than it saved.
This commit is contained in:
Paul Bellamy committed 2015-10-12 15:53:07 +01:00
1 parent fbb2c213a9
commit 375fd9140b
3 files changed
+35 -49

No files matched your search

+6 -13
View File
@@ -31,16 +31,7 @@ func (j jsonObject) Object(key string) (jsonObject, error) {
return jsonObject(result), nil
}
// For parsing json objects. Look up (or create) a string in the given map.
func (j jsonObject) String(key string, ks ...string) (string, error) {
if len(ks) > 0 {
j, err := j.Object(key)
if err != nil {
return "", err
}
return j.String(ks[0], ks[1:]...)
}
func (j jsonObject) String(key string) (string, error) {
iface, ok := j[key]
if !ok || iface == nil {
return "", nil
@@ -54,7 +45,6 @@ func (j jsonObject) String(key string, ks ...string) (string, error) {
return result, nil
}
// For parsing json objects. Look up (or create) a string array in the given map.
func (j jsonObject) StringArray(key string) ([]string, error) {
iface, ok := j[key]
if !ok || iface == nil {
@@ -62,6 +52,8 @@ func (j jsonObject) StringArray(key string) ([]string, error) {
}
switch o := iface.(type) {
case string:
return []string{o}, nil
case []string:
return o, nil
case []interface{}:
@@ -70,10 +62,11 @@ func (j jsonObject) StringArray(key string) ([]string, error) {
if s, ok := s.(string); ok {
result = append(result, s)
} else {
return nil, &UnmarshalWrongTypeError{key, "array of strings", iface}
return nil, &UnmarshalWrongTypeError{key, "string or array of strings", iface}
}
}
return result, nil
}
return nil, &UnmarshalWrongTypeError{key, "array of strings", iface}
return nil, &UnmarshalWrongTypeError{key, "string or array of strings", iface}
}