本文整理汇总了Golang中github.com/hraban/web.Context.Header方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Header方法的具体用法?Golang Context.Header怎么用?Golang Context.Header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/hraban/web.Context
的用法示例。
在下文中一共展示了Context.Header方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: redirect
func redirect(ctx *web.Context, loc *url.URL) {
if _, ok := ctx.Params["noredirect"]; ok {
return
}
loc = ctx.Request.URL.ResolveReference(loc)
ctx.Header().Set("Location", loc.String())
ctx.WriteHeader(303)
fmt.Fprintf(ctx, "redirecting to %s", loc)
}
示例2: handleGetCmdInfo
func handleGetCmdInfo(ctx *web.Context, idstr string) error {
id, _ := liblush.ParseCmdId(idstr)
s := ctx.User.(*server)
c := s.session.GetCommand(id)
if c == nil {
return web.WebError{404, "no such command: " + idstr}
}
ctx.Header().Set("content-type", "application/json")
enc := json.NewEncoder(ctx)
var info = struct {
Started, Exited *time.Time
Error string `json:",omitempty"`
}{
Started: c.Status().Started(),
Exited: c.Status().Exited(),
}
if cerr := c.Status().Err(); cerr != nil {
info.Error = cerr.Error()
}
return enc.Encode(info)
}