Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbellamy committed Oct 12, 2015
1 parent 95c910f commit 99ae2bf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
13 changes: 1 addition & 12 deletions proxy/create_container_interceptor.go
Expand Up @@ -82,17 +82,7 @@ func (i *createContainerInterceptor) setWeaveWaitEntrypoint(container jsonObject
var entrypoint []string
entrypoint, err := container.StringArray("Entrypoint")
if err != nil {
err, ok := err.(*UnmarshalWrongTypeError)
if !ok {
return err
}

got, ok := err.Got.(string)
if !ok {
return err
}

entrypoint = []string{got}
return err
}

cmd, err := container.StringArray("Cmd")
Expand Down Expand Up @@ -146,7 +136,6 @@ func (i *createContainerInterceptor) setHostname(container jsonObject, name, dns
if len(name)+1+len(trimmedDNSDomain) > MaxDockerHostname {
Log.Warningf("Container name [%s] too long to be used as hostname", name)
} else {
hostname = name
container["Hostname"] = name
container["Domainname"] = trimmedDNSDomain
}
Expand Down
8 changes: 4 additions & 4 deletions proxy/json.go
Expand Up @@ -31,7 +31,6 @@ 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)
Expand All @@ -54,14 +53,15 @@ 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 {
return nil, nil
}

switch o := iface.(type) {
case string:
return []string{o}, nil
case []string:
return o, nil
case []interface{}:
Expand All @@ -70,10 +70,10 @@ 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}
}
12 changes: 9 additions & 3 deletions proxy/json_test.go
Expand Up @@ -101,10 +101,16 @@ func TestLookupStringArray(t *testing.T) {
nil,
},
{
jsonObject{"string": "foo"},
"string",
jsonObject{"a": "foo"},
"a",
[]string{"foo"},
nil,
},
{
jsonObject{"int": 5},
"int",
nil,
&UnmarshalWrongTypeError{Field: "string", Expected: "array of strings", Got: "foo"},
&UnmarshalWrongTypeError{Field: "int", Expected: "string or array of strings", Got: 5},
},
}
for _, test := range tests {
Expand Down

0 comments on commit 99ae2bf

Please sign in to comment.