• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang yarf.Context类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/yarf-framework/yarf.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Context类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: TestResourceHello

func TestResourceHello(t *testing.T) {
	h := new(Hello)

	c := new(yarf.Context)
	c.Request, _ = http.NewRequest("GET", "/", nil)
	c.Response = httptest.NewRecorder()

	err := h.Get(c)
	if err != nil {
		t.Error(err.Error())
	}
}
开发者ID:yarf-framework,项目名称:yarf,代码行数:12,代码来源:resource_test.go


示例5: 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


示例6: PreDispatch

// PreDispatch wraps the http.ResponseWriter with a new LoggerWritter
// so we can log information about the response.
func (l *Logger) PreDispatch(c *yarf.Context) error {
	c.Response = &LoggerWriter{
		Writer: c.Response,
	}

	return nil
}
开发者ID:yarf-framework,项目名称:extras,代码行数:9,代码来源:yarf_middleware.go


示例7: TestExtra

func TestExtra(t *testing.T) {
	e := new(ExtraMiddleware)

	c := new(yarf.Context)
	c.Request, _ = http.NewRequest("GET", "/", nil)
	c.Response = httptest.NewRecorder()

	err := e.PreDispatch(c)
	if err != nil {
		t.Error(err.Error())
	}

	err = e.PostDispatch(c)
	if err != nil {
		t.Error(err.Error())
	}
}
开发者ID:yarf-framework,项目名称:yarf,代码行数:17,代码来源:middleware_test.go


示例8: TestHello

func TestHello(t *testing.T) {
	h := new(Hello)

	c := new(yarf.Context)
	c.Request, _ = http.NewRequest("GET", "/", nil)
	c.Response = httptest.NewRecorder()

	err := h.PreDispatch(c)
	if err != nil {
		t.Error(err.Error())
	}

	err = h.PostDispatch(c)
	if err != nil {
		t.Error(err.Error())
	}
}
开发者ID:yarf-framework,项目名称:yarf,代码行数:17,代码来源:hello_test.go


示例9: End

func (l *Logger) End(c *yarf.Context) error {
	// If nobody sets the status code, it's a 200
	var code int
	if _, ok := c.Response.(*LoggerWriter); ok {
		code = c.Response.(*LoggerWriter).StatusCode
	}

	if code == 0 {
		code = 200
	}

	log.Printf(
		"| %s | %s | %d | %s",
		c.GetClientIP(),
		c.Request.Method,
		code,
		c.Request.URL.String(),
	)

	return nil
}
开发者ID:yarf-framework,项目名称:extras,代码行数:21,代码来源:yarf_middleware.go


示例10: 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


示例11: 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


示例12: Get

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

	return nil
}
开发者ID:dlsniper,项目名称:benchmarks,代码行数:5,代码来源:param_test.go


示例13: Get

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

	return nil
}
开发者ID:dlsniper,项目名称:benchmarks,代码行数:5,代码来源:simple_test.go


示例14: PreDispatch

// PreDispatch creates the StrData object and sets it on the Context.Data property.
func (m *SetStrData) PreDispatch(c *yarf.Context) error {
	c.Data = new(StrData)

	return nil
}
开发者ID:yarf-framework,项目名称:extras,代码行数:6,代码来源:yarf_middleware.go


示例15: PostDispatch

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

	return nil
}
开发者ID:jhautefeuille,项目名称:yarf,代码行数:5,代码来源:middleware.go


示例16: 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


示例17: 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



注:本文中的github.com/yarf-framework/yarf.Context类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang scrape.Attr函数代码示例发布时间:2022-05-28
下一篇:
Golang oss.Client类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap