(f handlerFunc)
| 548 | } |
| 549 | |
| 550 | func (h *Handler) All(f handlerFunc) http.HandlerFunc { |
| 551 | return func(w http.ResponseWriter, r *http.Request) { |
| 552 | h.handleError(w, r, func() error { |
| 553 | // TODO: return correct "success" status |
| 554 | status := 200 |
| 555 | start := time.Now() |
| 556 | |
| 557 | defer func() { |
| 558 | if e := recover(); e != nil { |
| 559 | log.Error("%s:\n%s", e, debug.Stack()) |
| 560 | impart.WriteError(w, impart.HTTPError{http.StatusInternalServerError, "Something didn't work quite right."}) |
| 561 | status = 500 |
| 562 | } |
| 563 | |
| 564 | log.Info(h.app.ReqLog(r, status, time.Since(start))) |
| 565 | }() |
| 566 | |
| 567 | // TODO: do any needed authentication |
| 568 | |
| 569 | err := f(h.app.App(), w, r) |
| 570 | if err != nil { |
| 571 | if err, ok := err.(impart.HTTPError); ok { |
| 572 | status = err.Status |
| 573 | } else { |
| 574 | status = 500 |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | return err |
| 579 | }()) |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | func (h *Handler) PlainTextAPI(f handlerFunc) http.HandlerFunc { |
| 584 | return func(w http.ResponseWriter, r *http.Request) { |
no test coverage detected