本文整理汇总了Golang中github.com/yarf-framework/yarf.Context.Render方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Render方法的具体用法?Golang Context.Render怎么用?Golang Context.Render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/yarf-framework/yarf.Context
的用法示例。
在下文中一共展示了Context.Render方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Get
// Implement a GET handler that panics
func (p *Panic) Get(c *yarf.Context) error {
c.Render("I'm panicking!")
panic("Totally panicking!")
return nil
}
示例2: Get
// Get implements a GET handler that panics
func (p *Panic) Get(c *yarf.Context) error {
c.Render("I'm panicking!")
panic("Totally panicking!")
// The next line is unreachable (govet)
//return nil
}
示例3: Render
// Render reads the content of the path built using the name param together with the object properties.
// It outputs the content of the readed file or returns an error if that fails.
func (l *LayoutMiddleware) Render(name string, c *yarf.Context) error {
content, err := l.Cached(l.TplPath + "/" + l.TplName + "/layout/" + name + ".tpl")
if err != nil {
return yarf.ErrorNotFound()
}
c.Render(content)
return nil
}
示例4: Get
// Get implements the GET handler with optional name parameter
func (h *HelloV2) Get(c *yarf.Context) error {
name := c.Param("name")
salute := "(v2) Hello"
if name != "" {
salute += ", " + name
}
salute += "!"
c.Render(salute)
return nil
}
示例5: Render
// Render reads the content of the path built using the c.URL.Path together with the object's TplPath.
// It outputs the content of the readed file or returns an error if that fails.
func (v *ViewResource) Render(c *yarf.Context) error {
pre, err := v.Cached(v.TplPath + "/" + v.TplName + "/layout/pre.tpl")
if err != nil {
return yarf.ErrorNotFound()
}
content, err := v.Cached(v.TplPath + "/" + v.TplName + "/view" + strings.TrimSuffix(c.Request.URL.EscapedPath(), "/") + ".tpl")
if err != nil {
// Try index.tpl
content, err = v.Cached(v.TplPath + "/" + v.TplName + "/view" + strings.TrimSuffix(c.Request.URL.EscapedPath(), "/") + "/index.tpl")
if err != nil {
return yarf.ErrorNotFound()
}
}
post, err := v.Cached(v.TplPath + "/" + v.TplName + "/layout/post.tpl")
if err != nil {
return yarf.ErrorNotFound()
}
c.Render(pre)
c.Render(content)
c.Render(post)
return nil
}
示例6: Get
func (y *YarfParam) Get(c *yarf.Context) error {
c.Render("Hello, " + c.Param("name"))
return nil
}
示例7: Get
func (y *YarfMulti) Get(c *yarf.Context) error {
c.Render("Hello " + c.Param("name1") + "," + c.Param("name2") + "," + c.Param("name3") + "," + c.Param("name4"))
return nil
}
示例8: Get
func (y *YarfHello) Get(c *yarf.Context) error {
c.Render("Hello world!")
return nil
}
示例9: PostDispatch
// PostDispatch includes code to be executed after every Resource request.
func (m *HelloMiddleware) PostDispatch(c *yarf.Context) error {
c.Render("\n\nGoodbye from middleware!")
return nil
}
示例10: PreDispatch
// PreDispatch renders a hardcoded string
func (m *HelloMiddleware) PreDispatch(c *yarf.Context) error {
c.Render("Hello from middleware! \n\n")
return nil
}
示例11: PostDispatch
func (m *ExtraMiddleware) PostDispatch(c *yarf.Context) error {
c.Render("\n\nExtra from nested middleware!")
return nil
}