当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.Write方法代码示例

本文整理汇总了Golang中web.Context.Write方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Write方法的具体用法?Golang Context.Write怎么用?Golang Context.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在web.Context的用法示例。


在下文中一共展示了Context.Write方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: getStyle

func getStyle(context *web.Context) {
	b, err := ioutil.ReadFile("style.css")
	context.SetHeader("Content-Type", "text/css", true)
	if err != nil {
		context.WriteString(err.String())
	}

	context.Write(b)
}
开发者ID:gentoomen,项目名称:gentoomen.org-go,代码行数:9,代码来源:main.go

示例2: pageRouter

func pageRouter(ctx *web.Context, route string) {
	switch route {
	case "search":
		json, e := Search(ctx)
		if e != nil {
			ctx.WriteString(e.String())
		}
		ctx.Write(json)
	default:

	}
}
开发者ID:angelini,项目名称:LogGo,代码行数:12,代码来源:api.go

示例3: info

// function to display the info about a KurzUrl given by it's Key
func info(ctx *web.Context, short string) {

	if strings.HasSuffix(short, "+") {
		short = strings.Replace(short, "+", "", 1)
	}
	kurl, err := load(short)
	if err == nil {
		ctx.SetHeader("Content-Type", "application/json", true)
		ctx.Write(kurl.Json())
		ctx.WriteString("\n")
	} else {
		ctx.Redirect(http.StatusNotFound, ROLL)
	}
}
开发者ID:vormplus,项目名称:kurz.go,代码行数:15,代码来源:kurz.go

示例4: latest

//Returns a json array with information about the last shortened urls. If data
// is a valid integer, that's the amount of data it will return, otherwise
// a maximum of 10 entries will be returned.
func latest(ctx *web.Context, data string) {
	howmany, err := strconv.Atoi64(data)
	if err != nil {
		howmany = 10
	}
	c, _ := redis.Get(COUNTER)

	last := c.Int64()
	upTo := (last - howmany)

	ctx.SetHeader("Content-Type", "application/json", true)
	ctx.WriteString("{ \"urls\" : [")
	for i := last; i > upTo && i > 0; i -= 1 {
		kurl, err := load(Encode(i))
		if err == nil {
			ctx.Write(kurl.Json())
			if i != upTo+1 {
				ctx.WriteString(",")
			}
		}
	}
	ctx.WriteString("] }")
	ctx.WriteString("\n")
}
开发者ID:vormplus,项目名称:kurz.go,代码行数:27,代码来源:kurz.go


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