intFromQueryParam checks for name as a query param, converts it to uint64 and returns it. It also writes any errors to w. A bool is returned to indicate if the param was parsed successfully.
(w http.ResponseWriter, r *http.Request, name string)
| 27 | // It also writes any errors to w. A bool is returned to indicate if the param was parsed |
| 28 | // successfully. |
| 29 | func intFromQueryParam(w http.ResponseWriter, r *http.Request, name string) (uint64, bool) { |
| 30 | str := r.URL.Query().Get(name) |
| 31 | if len(str) == 0 { |
| 32 | w.WriteHeader(http.StatusBadRequest) |
| 33 | x.SetStatus(w, x.ErrorInvalidRequest, fmt.Sprintf("%s not passed", name)) |
| 34 | return 0, false |
| 35 | } |
| 36 | val, err := strconv.ParseUint(str, 0, 64) |
| 37 | if err != nil { |
| 38 | w.WriteHeader(http.StatusBadRequest) |
| 39 | x.SetStatus(w, x.ErrorInvalidRequest, fmt.Sprintf("Error while parsing %s", name)) |
| 40 | return 0, false |
| 41 | } |
| 42 | return val, true |
| 43 | } |
| 44 | |
| 45 | func (st *state) assign(w http.ResponseWriter, r *http.Request) { |
| 46 | x.AddCorsHeaders(w) |
no test coverage detected