MCPcopy
hub / github.com/writefreely/writefreely / All

Method All

handle.go:550–581  ·  view source on GitHub ↗
(f handlerFunc)

Source from the content-addressed store, hash-verified

548}
549
550func (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
583func (h *Handler) PlainTextAPI(f handlerFunc) http.HandlerFunc {
584 return func(w http.ResponseWriter, r *http.Request) {

Callers 2

InitRoutesFunction · 0.80
RouteCollectionsFunction · 0.80

Calls 4

handleErrorMethod · 0.95
ReqLogMethod · 0.65
AppMethod · 0.65
fFunction · 0.50

Tested by

no test coverage detected