// preparebase.Context sets view,config and model on the ctx. func (r *Router) prepareContext(ctx *base.Context) { if r.Options != nil { if r.Options.View != nil { ctx.Set(r.Options.View) } if r.Options.Config != nil { ctx.Cfg = r.Options.Config } if r.Options.Model != nil { ctx.DB = r.Options.Model } if r.Options.Log != nil { ctx.Log = r.Options.Log } if r.Options.SessionStore != nil { ctx.SessionStore = r.Options.SessionStore } } // It is a good idea to ensure that a well prepared context always has the // Log field set. if ctx.Log == nil { ctx.Log = defaultLogger } }
// 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 } }