本文整理汇总了Golang中github.com/urandom/webfw/context.Context.GetAll方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.GetAll方法的具体用法?Golang Context.GetAll怎么用?Golang Context.GetAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/urandom/webfw/context.Context
的用法示例。
在下文中一共展示了Context.GetAll方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GetRenderCtx
// GetRenderCtx returns a RenderCtx wrapper around the current raw renderer
// The wrapper automatically adds the current request ContextData to the
// renderer's Render method call.
func GetRenderCtx(c context.Context, r *http.Request) renderer.RenderCtx {
rnd := GetRenderer(c)
return renderer.RenderCtx(func(w io.Writer, data renderer.RenderData, names ...string) error {
return rnd.Render(w, data, c.GetAll(r), names...)
})
}
示例2: Handler
func (con App) Handler(c context.Context) http.Handler {
cfg := readeef.GetConfig(c)
rnd := webfw.GetRenderer(c)
if cfg.Logger.Level == "debug" {
rnd.SkipCache(true)
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
action := webfw.GetMultiPatternIdentifier(c, r)
data := renderer.RenderData{}
if action == "history" {
params := webfw.GetParams(c, r)
data["history"] = "/web/" + params["history"]
}
if r.Method != "HEAD" {
err := rnd.Render(w, data, c.GetAll(r), "app.tmpl")
if err != nil {
webfw.GetLogger(c).Print(err)
}
}
w.Header().Set("X-Readeef", "1")
})
}
示例3: Handler
func (con Component) Handler(c context.Context) http.Handler {
mw, i18nFound := con.dispatcher.Middleware("I18N")
logger := webfw.GetLogger(c)
rnd := renderer.NewRenderer(con.dispatcher.Config.Renderer.Dir, "raw.tmpl")
rnd.Delims("{%", "%}")
if i18nFound {
if i18n, ok := mw.(middleware.I18N); ok {
rnd.Funcs(i18n.TemplateFuncMap())
}
} else {
logger.Infoln("I18N middleware not found")
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
params := webfw.GetParams(c, r)
err := rnd.Render(w, renderer.RenderData{"apiPattern": con.apiPattern},
c.GetAll(r), "components/"+params["name"]+".tmpl")
if err != nil {
webfw.GetLogger(c).Print(err)
}
})
}
示例4: Handler
func (con App) Handler(c context.Context) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
rnd := webfw.GetRenderer(c)
err := rnd.Render(w, nil, c.GetAll(r), "app.tmpl")
if err != nil {
webfw.GetLogger(c).Print(err)
}
}
}
示例5: Handler
func (con Component) Handler(c context.Context) http.HandlerFunc {
rnd := renderer.NewRenderer(con.dir, "raw.tmpl")
rnd.Delims("{%", "%}")
return func(w http.ResponseWriter, r *http.Request) {
params := webfw.GetParams(c, r)
err := rnd.Render(w, renderer.RenderData{"apiPattern": con.apiPattern},
c.GetAll(r), "components/"+params["name"]+".tmpl")
if err != nil {
webfw.GetLogger(c).Print(err)
}
}
}
示例6: Handler
func (con App) Handler(c context.Context) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
rnd := webfw.GetRenderer(c)
action := webfw.GetMultiPatternIdentifier(c, r)
data := renderer.RenderData{}
if action == "history" {
params := webfw.GetParams(c, r)
data["history"] = "/web/" + params["history"]
}
err := rnd.Render(w, data, c.GetAll(r), "app.tmpl")
if err != nil {
webfw.GetLogger(c).Print(err)
}
})
}
示例7: Handler
func (con Component) Handler(c context.Context) http.Handler {
i18nmw, i18nFound := con.dispatcher.Middleware("I18N")
urlmw, urlFound := con.dispatcher.Middleware("Url")
logger := webfw.GetLogger(c)
cfg := readeef.GetConfig(c)
rnd := renderer.NewRenderer(con.dispatcher.Config.Renderer.Dir, "raw.tmpl")
rnd.Delims("{%", "%}")
if cfg.Logger.Level == "debug" {
rnd.SkipCache(true)
}
if i18nFound {
if i18n, ok := i18nmw.(middleware.I18N); ok {
rnd.Funcs(i18n.TemplateFuncMap())
}
} else {
logger.Infoln("I18N middleware not found")
}
if urlFound {
if url, ok := urlmw.(middleware.Url); ok {
rnd.Funcs(url.TemplateFuncMap(c))
}
} else {
logger.Infoln("Url middleware not found")
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
params := webfw.GetParams(c, r)
if r.Method != "HEAD" {
err := rnd.Render(w, renderer.RenderData{"apiPattern": con.apiPattern, "config": cfg},
c.GetAll(r), "components/"+params["name"]+".tmpl")
if err != nil {
webfw.GetLogger(c).Print(err)
}
}
})
}