diff --git a/api/server/form.go b/api/server/form.go index af1cd2075e..75584df065 100644 --- a/api/server/form.go +++ b/api/server/form.go @@ -11,7 +11,7 @@ func boolValue(r *http.Request, k string) bool { return !(s == "" || s == "0" || s == "no" || s == "false" || s == "none") } -func int64Value(r *http.Request, k string) int64 { +func int64ValueOrZero(r *http.Request, k string) int64 { val, err := strconv.ParseInt(r.FormValue(k), 10, 64) if err != nil { return 0 diff --git a/api/server/form_test.go b/api/server/form_test.go index 5cf6c82c14..caa9f1757c 100644 --- a/api/server/form_test.go +++ b/api/server/form_test.go @@ -33,7 +33,7 @@ func TestBoolValue(t *testing.T) { } } -func TestInt64Value(t *testing.T) { +func TestInt64ValueOrZero(t *testing.T) { cases := map[string]int64{ "": 0, "asdf": 0, @@ -47,7 +47,7 @@ func TestInt64Value(t *testing.T) { r, _ := http.NewRequest("POST", "", nil) r.Form = v - a := int64Value(r, "test") + a := int64ValueOrZero(r, "test") if a != e { t.Fatalf("Value: %s, expected: %v, actual: %v", c, e, a) } diff --git a/api/server/server.go b/api/server/server.go index d1540acb84..fbc844ad2e 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -1295,10 +1295,10 @@ func (s *Server) postBuild(version version.Version, w http.ResponseWriter, r *ht buildConfig.ForceRemove = boolValue(r, "forcerm") buildConfig.AuthConfig = authConfig buildConfig.ConfigFile = configFile - buildConfig.MemorySwap = int64Value(r, "memswap") - buildConfig.Memory = int64Value(r, "memory") - buildConfig.CpuShares = int64Value(r, "cpushares") - buildConfig.CpuQuota = int64Value(r, "cpuquota") + buildConfig.MemorySwap = int64ValueOrZero(r, "memswap") + buildConfig.Memory = int64ValueOrZero(r, "memory") + buildConfig.CpuShares = int64ValueOrZero(r, "cpushares") + buildConfig.CpuQuota = int64ValueOrZero(r, "cpuquota") buildConfig.CpuSetCpus = r.FormValue("cpusetcpus") buildConfig.CpuSetMems = r.FormValue("cpusetmems")