Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't use go-dockerclient to en/decode inspects in the proxy
- Loading branch information
1 parent
570f3cb
commit 75fc999
Showing
4 changed files
with
73 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package proxy | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type UnmarshalWrongTypeError struct { | ||
Field, Expected string | ||
Got interface{} | ||
} | ||
|
||
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] | ||
if !ok || iface == nil { | ||
result := map[string]interface{}{} | ||
m[key] = result | ||
return result, nil | ||
} | ||
|
||
result, ok := iface.(map[string]interface{}) | ||
if !ok { | ||
return nil, &UnmarshalWrongTypeError{key, "object", iface} | ||
} | ||
|
||
return 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] | ||
if !ok || iface == nil { | ||
return "", nil | ||
} | ||
|
||
result, ok := iface.(string) | ||
if !ok { | ||
return "", &UnmarshalWrongTypeError{key, "string", iface} | ||
} | ||
|
||
return result, nil | ||
} |