Пример #1
0
// executes the method fn on Controller ctrl, it sets context.
func (r *Router) handleController(ctx *base.Context, fn string, ctrl controller.Controller) {
	ctrl.New(ctx)
	// execute the method
	// TODO: better error handling?
	if x := ita.New(ctrl).Call(fn); x.Error() != nil {
		ctx.Set(http.StatusInternalServerError)
		_, _ = ctx.Write([]byte(x.Error().Error()))
		ctx.TextPlain()
		_ = ctx.Commit()
		return
	}
	err := ctx.Commit()
	if err != nil {
		//TODO:  Log error
	}
}
Пример #2
0
// executes the method fn on Controller ctrl, it sets context.
func (r *Router) handleController(w http.ResponseWriter, req *http.Request, fn string, ctrl Controller) {
	ctx := NewContext(w, req)
	r.prepareContext(ctx)
	ctrl.New(ctx)

	// execute the method
	// TODO: better error handling?
	if x := ita.New(ctrl).Call(fn); x.Error() != nil {
		ctx.Set(http.StatusInternalServerError)
		ctx.Write([]byte(x.Error().Error()))
		ctx.TextPlain()
		ctx.Commit()
		return
	}
	err := ctrl.Render()
	if err != nil {
		logThis.Errors(err)
	}
}