本文整理汇总了Golang中github.com/coffeehc/web.Reply.OpenStream方法的典型用法代码示例。如果您正苦于以下问题:Golang Reply.OpenStream方法的具体用法?Golang Reply.OpenStream怎么用?Golang Reply.OpenStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coffeehc/web.Reply
的用法示例。
在下文中一共展示了Reply.OpenStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: reqInfoHandler
func reqInfoHandler(r *http.Request, param map[string]string, reply *web.Reply) {
stream := reply.OpenStream()
fmt.Fprintf(stream, "Method: %s\n", r.Method)
fmt.Fprintf(stream, "Protocol: %s\n", r.Proto)
fmt.Fprintf(stream, "Host: %s\n", r.Host)
fmt.Fprintf(stream, "RemoteAddr: %s\n", r.RemoteAddr)
fmt.Fprintf(stream, "RequestURI: %q\n", r.RequestURI)
fmt.Fprintf(stream, "URL: %#v\n", r.URL)
fmt.Fprintf(stream, "Body.ContentLength: %d (-1 means unknown)\n", r.ContentLength)
fmt.Fprintf(stream, "Close: %v (relevant for HTTP/1 only)\n", r.Close)
fmt.Fprintf(stream, "TLS: %#v\n", r.TLS)
fmt.Fprintf(stream, "\nHeaders:\n")
r.Header.Write(stream)
}
示例2: TestService
func TestService(request *http.Request, param map[string]string, reply *web.Reply) {
stream := reply.OpenStream()
clientGone := stream.CloseNotify()
ticker := time.NewTicker(1 * time.Second)
defer ticker.Stop()
fmt.Fprintf(stream, "# ~1KB of junk to force browsers to start rendering immediately: \n")
io.WriteString(stream, strings.Repeat("# xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", 13))
for {
fmt.Fprintf(stream, "%v\n", time.Now())
stream.Flush()
select {
case <-ticker.C:
case <-clientGone:
log.Printf("Client %v disconnected from the clock", request.RemoteAddr)
return
}
}
}