From 427e1d7622757060baf56c747664e06e2991a799 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Fri, 18 Dec 2015 13:25:32 -0500 Subject: [PATCH] Remove usage of runconfig.ConvertKVStringsToMap in the API client library. It's a very simple function that we can duplicate. Signed-off-by: David Calavera --- client/image_build.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/client/image_build.go b/client/image_build.go index ffe8b42..364a921 100644 --- a/client/image_build.go +++ b/client/image_build.go @@ -7,6 +7,7 @@ import ( "net/url" "regexp" "strconv" + "strings" "github.com/docker/docker/api/types" "github.com/docker/docker/runconfig" @@ -101,7 +102,7 @@ func imageBuildOptionsToQuery(options types.ImageBuildOptions) (url.Values, erro } query.Set("ulimits", string(ulimitsJSON)) - buildArgs := runconfig.ConvertKVStringsToMap(options.BuildArgs) + buildArgs := convertKVStringsToMap(options.BuildArgs) buildArgsJSON, err := json.Marshal(buildArgs) if err != nil { return query, err @@ -119,3 +120,18 @@ func getDockerOS(serverHeader string) string { } return osType } + +// convertKVStringsToMap converts ["key=value"] to {"key":"value"} +func convertKVStringsToMap(values []string) map[string]string { + result := make(map[string]string, len(values)) + for _, value := range values { + kv := strings.SplitN(value, "=", 2) + if len(kv) == 1 { + result[kv[0]] = "" + } else { + result[kv[0]] = kv[1] + } + } + + return result +}