當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Context.Render方法代碼示例

本文整理匯總了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
}
開發者ID:jhautefeuille,項目名稱:yarf,代碼行數:8,代碼來源:main.go

示例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
}
開發者ID:yarf-framework,項目名稱:yarf,代碼行數:9,代碼來源:main.go

示例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
}
開發者ID:yarf-framework,項目名稱:extras,代碼行數:12,代碼來源:layout.go

示例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
}
開發者ID:yarf-framework,項目名稱:yarf,代碼行數:14,代碼來源:resource.go

示例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
}
開發者ID:yarf-framework,項目名稱:extras,代碼行數:28,代碼來源:view.go

示例6: Get

func (y *YarfParam) Get(c *yarf.Context) error {
	c.Render("Hello, " + c.Param("name"))

	return nil
}
開發者ID:dlsniper,項目名稱:benchmarks,代碼行數:5,代碼來源:param_test.go

示例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
}
開發者ID:yarf-framework,項目名稱:benchmarks,代碼行數:5,代碼來源:multi_test.go

示例8: Get

func (y *YarfHello) Get(c *yarf.Context) error {
	c.Render("Hello world!")

	return nil
}
開發者ID:dlsniper,項目名稱:benchmarks,代碼行數:5,代碼來源:simple_test.go

示例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
}
開發者ID:yarf-framework,項目名稱:yarf,代碼行數:6,代碼來源:middleware.go

示例10: PreDispatch

// PreDispatch renders a hardcoded string
func (m *HelloMiddleware) PreDispatch(c *yarf.Context) error {
	c.Render("Hello from middleware! \n\n")

	return nil
}
開發者ID:yarf-framework,項目名稱:yarf,代碼行數:6,代碼來源:middleware.go

示例11: PostDispatch

func (m *ExtraMiddleware) PostDispatch(c *yarf.Context) error {
	c.Render("\n\nExtra from nested middleware!")

	return nil
}
開發者ID:jhautefeuille,項目名稱:yarf,代碼行數:5,代碼來源:middleware.go


注:本文中的github.com/yarf-framework/yarf.Context.Render方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。