(w http.ResponseWriter, jsonObject interface{})
| 203 | } |
| 204 | |
| 205 | func sendJSON(w http.ResponseWriter, jsonObject interface{}) { |
| 206 | w.Header().Set("Content-Type", "application/json") |
| 207 | // Marshalling might fail, in which case we should return a 500 with the |
| 208 | // actual error. |
| 209 | bs, err := json.MarshalIndent(jsonObject, "", " ") |
| 210 | if err != nil { |
| 211 | // This Marshal() can't fail though. |
| 212 | bs, _ = json.Marshal(map[string]string{"error": err.Error()}) |
| 213 | http.Error(w, string(bs), http.StatusInternalServerError) |
| 214 | return |
| 215 | } |
| 216 | fmt.Fprintf(w, "%s\n", bs) |
| 217 | } |
| 218 | |
| 219 | func (s *service) Serve(ctx context.Context) error { |
| 220 | listener, err := s.getListener(s.cfg.GUI()) |
no test coverage detected