func GetConfig(c context.Context) Config { if v, ok := c.GetGlobal(CtxKey("config")); ok { return v.(Config) } return Config{} }
func GetRepo(c context.Context) content.Repo { if v, ok := c.GetGlobal(CtxKey("repo")); ok { return v.(content.Repo) } return nil }
// GetLogger returns the error logger, to be used if an error occurs during // a request. func GetLogger(c context.Context) Logger { if val, ok := c.GetGlobal(context.BaseCtxKey("logger")); ok { return val.(Logger) } return NewStandardLogger(os.Stderr, "", 0) }
// GetRenderer returns the current raw renderer from the context. func GetRenderer(c context.Context) renderer.Renderer { if val, ok := c.GetGlobal(context.BaseCtxKey("renderer")); ok { return val.(renderer.Renderer) } return renderer.NewRenderer("template", "base.tmpl") }
// GetConfig is a helper function for getting the current config // from the request context. func GetConfig(c context.Context) Config { if val, ok := c.GetGlobal(context.BaseCtxKey("config")); ok { return val.(Config) } return Config{} }
func GetDB(c context.Context) DB { if v, ok := c.GetGlobal(CtxKey("db")); ok { return v.(DB) } conf := GetConfig(c) db := NewDB(conf.DB.Driver, conf.DB.Connect) if err := db.Connect(); err != nil { panic(err) } return db }
// GetDispatcher returns the request dispatcher. func GetDispatcher(c context.Context) *Dispatcher { if val, ok := c.GetGlobal(context.BaseCtxKey("dispatcher")); ok { return val.(*Dispatcher) } return &Dispatcher{} }