本文整理匯總了Golang中einvite/framework.WebContext.Header方法的典型用法代碼示例。如果您正苦於以下問題:Golang WebContext.Header方法的具體用法?Golang WebContext.Header怎麽用?Golang WebContext.Header使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類einvite/framework.WebContext
的用法示例。
在下文中一共展示了WebContext.Header方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Write
//adapted from Revel framework BinaryResult.Apply method
func (r *StreamResult) Write(ctx framework.WebContext) error {
var err error
// If we have a ReadSeeker, delegate to http.ServeContent
if rs, ok := r.Reader.(io.ReadSeeker); ok {
http.ServeContent(ctx, ctx.Req(), r.Name, r.ModTime, rs)
} else {
// Else, do a simple io.Copy.
if r.Length != -1 {
ctx.Header().Set("Content-Length", strconv.FormatInt(r.Length, 10))
}
ctx.WriteHeader(http.StatusOK)
//TODO: use a mime-type to file extension strategy like Revel does
//ctx.ContentType("application/octet-stream")
//ctx.ContentType(ContentTypeByFilename(r.Name))
_, err = io.Copy(ctx, r.Reader)
}
// Close the Reader if we can
if v, ok := r.Reader.(io.Closer); ok {
v.Close()
}
return err
}
示例2: Test
func (this EventController) Test(ctx framework.WebContext) framework.WebResult {
//note: time.sleep frees the thread and allows other goroutines to execute
//sending 1000 concurrent requests with AB all complete within 5seconds
time.Sleep(1 * time.Second)
fmt.Println(ctx.Header())
fmt.Println("Test invoked")
return ctx.Text("test operation")
}