MCPcopy
hub / github.com/perkeep/perkeep / OptionalInt

Function OptionalInt

internal/httputil/httputil.go:244–254  ·  view source on GitHub ↗

OptionalInt returns the integer in req given by param, or 0 if not present. If the form value is not an integer, it panics with a a value understood by Recover or RecoverJSON.

(req *http.Request, param string)

Source from the content-addressed store, hash-verified

242// OptionalInt returns the integer in req given by param, or 0 if not present.
243// If the form value is not an integer, it panics with a a value understood by Recover or RecoverJSON.
244func OptionalInt(req *http.Request, param string) int {
245 v := req.FormValue(param)
246 if v == "" {
247 return 0
248 }
249 i, err := strconv.Atoi(v)
250 if err != nil {
251 panic(InvalidParameterError(param))
252 }
253 return i
254}
255
256// ServeJSONError sends a JSON error response to rw for the provided
257// error value.

Callers 1

fromHTTPGetMethod · 0.92

Calls 1

InvalidParameterErrorTypeAlias · 0.85

Tested by

no test coverage detected