MCPcopy
hub / github.com/writefreely/writefreely / UserAll

Method UserAll

handle.go:316–360  ·  view source on GitHub ↗
(web bool, f userHandlerFunc, a authFunc)

Source from the content-addressed store, hash-verified

314}
315
316func (h *Handler) UserAll(web bool, f userHandlerFunc, a authFunc) http.HandlerFunc {
317 return func(w http.ResponseWriter, r *http.Request) {
318 handleFunc := func() error {
319 var status int
320 start := time.Now()
321
322 defer func() {
323 if e := recover(); e != nil {
324 log.Error("%s: %s", e, debug.Stack())
325 impart.WriteError(w, impart.HTTPError{http.StatusInternalServerError, "Something didn't work quite right."})
326 status = 500
327 }
328
329 log.Info(h.app.ReqLog(r, status, time.Since(start)))
330 }()
331
332 u, err := a(h.app.App(), r)
333 if err != nil {
334 if err, ok := err.(impart.HTTPError); ok {
335 status = err.Status
336 } else {
337 status = 500
338 }
339 return err
340 }
341
342 err = f(h.app.App(), u, w, r)
343 if err == nil {
344 status = 200
345 } else if err, ok := err.(impart.HTTPError); ok {
346 status = err.Status
347 } else {
348 status = 500
349 }
350
351 return err
352 }
353
354 if web {
355 h.handleHTTPError(w, r, handleFunc())
356 } else {
357 h.handleError(w, r, handleFunc())
358 }
359 }
360}
361
362func (h *Handler) RedirectOnErr(f handlerFunc, loc string) handlerFunc {
363 return func(app *App, w http.ResponseWriter, r *http.Request) error {

Callers 2

UserAPIMethod · 0.95
UserWebAPIMethod · 0.95

Calls 6

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

Tested by

no test coverage detected