(w http.ResponseWriter, r *http.Request, params httprouter.Params)
| 142 | } |
| 143 | |
| 144 | func (api *API) ServeV1Shape(w http.ResponseWriter, r *http.Request, params httprouter.Params) { |
| 145 | ctx, cancel := api.contextForRequest(r) |
| 146 | defer cancel() |
| 147 | select { |
| 148 | case <-ctx.Done(): |
| 149 | jsonResponse(w, http.StatusBadRequest, "Cancelled") |
| 150 | return |
| 151 | default: |
| 152 | } |
| 153 | h, err := api.GetHandleForRequest(r) |
| 154 | if err != nil { |
| 155 | jsonResponse(w, http.StatusBadRequest, err) |
| 156 | return |
| 157 | } |
| 158 | l := query.GetLanguage(params.ByName("query_lang")) |
| 159 | if l == nil { |
| 160 | jsonResponse(w, http.StatusBadRequest, "Unknown query language.") |
| 161 | return |
| 162 | } else if l.HTTP == nil { |
| 163 | jsonResponse(w, http.StatusBadRequest, "HTTP interface is not supported for this query language.") |
| 164 | return |
| 165 | } |
| 166 | ses := l.HTTP(h.QuadStore) |
| 167 | bodyBytes, err := ioutil.ReadAll(r.Body) |
| 168 | if err != nil { |
| 169 | jsonResponse(w, http.StatusBadRequest, err) |
| 170 | return |
| 171 | } |
| 172 | code := string(bodyBytes) |
| 173 | |
| 174 | output, err := GetQueryShape(code, ses) |
| 175 | if err == query.ErrParseMore { |
| 176 | jsonResponse(w, http.StatusBadRequest, "Incomplete data?") |
| 177 | return |
| 178 | } else if err != nil { |
| 179 | w.WriteHeader(http.StatusBadRequest) |
| 180 | WriteError(w, err) |
| 181 | return |
| 182 | } |
| 183 | w.Write(output) |
| 184 | } |
nothing calls this directly
no test coverage detected