[proxy] all request modification is done through map[string]interface{}

That way we are less likely fall victim to go-dockerclient, or the API changing.
This commit is contained in:
Paul Bellamy committed 2015-10-12 15:53:07 +01:00
1 parent d323de3c21
commit fbb2c213a9
9 files changed
+298 -78

No files matched your search

+41 -8
View File
@@ -13,12 +13,13 @@ func (e *UnmarshalWrongTypeError) Error() string {
return fmt.Sprintf("Wrong type for %s field, expected %s, but got %T", e.Field, e.Expected, e.Got)
}
// For parsing json objects. Look up (or create) a child object in the given map.
func lookupObject(m map[string]interface{}, key string) (map[string]interface{}, error) {
iface, ok := m[key]
type jsonObject map[string]interface{}
func (j jsonObject) Object(key string) (jsonObject, error) {
iface, ok := j[key]
if !ok || iface == nil {
result := map[string]interface{}{}
m[key] = result
result := jsonObject{}
j[key] = result
return result, nil
}
@@ -27,12 +28,20 @@ func lookupObject(m map[string]interface{}, key string) (map[string]interface{},
return nil, &UnmarshalWrongTypeError{key, "object", iface}
}
return result, nil
return jsonObject(result), nil
}
// For parsing json objects. Look up (or create) a string in the given map.
func lookupString(m map[string]interface{}, key string) (string, error) {
iface, ok := m[key]
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:]...)
}
iface, ok := j[key]
if !ok || iface == nil {
return "", nil
}
@@ -44,3 +53,27 @@ func lookupString(m map[string]interface{}, key 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 {
return nil, nil
}
switch o := iface.(type) {
case []string:
return o, nil
case []interface{}:
result := []string{}
for _, s := range o {
if s, ok := s.(string); ok {
result = append(result, s)
} else {
return nil, &UnmarshalWrongTypeError{key, "array of strings", iface}
}
}
return result, nil
}
return nil, &UnmarshalWrongTypeError{key, "array of strings", iface}
}