github.com/tsuna/docker@v1.7.0-rc3/api/server/form.go (about) 1 package server 2 3 import ( 4 "net/http" 5 "strconv" 6 "strings" 7 ) 8 9 func boolValue(r *http.Request, k string) bool { 10 s := strings.ToLower(strings.TrimSpace(r.FormValue(k))) 11 return !(s == "" || s == "0" || s == "no" || s == "false" || s == "none") 12 } 13 14 // boolValueOrDefault returns the default bool passed if the query param is 15 // missing, otherwise it's just a proxy to boolValue above 16 func boolValueOrDefault(r *http.Request, k string, d bool) bool { 17 if _, ok := r.Form[k]; !ok { 18 return d 19 } 20 return boolValue(r, k) 21 } 22 23 func int64ValueOrZero(r *http.Request, k string) int64 { 24 val, err := strconv.ParseInt(r.FormValue(k), 10, 64) 25 if err != nil { 26 return 0 27 } 28 return val 29 }