本文整理匯總了Golang中github.com/convox/rack/Godeps/_workspace/src/golang.org/x/net/websocket.Conn.Write方法的典型用法代碼示例。如果您正苦於以下問題:Golang Conn.Write方法的具體用法?Golang Conn.Write怎麽用?Golang Conn.Write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/convox/rack/Godeps/_workspace/src/golang.org/x/net/websocket.Conn
的用法示例。
在下文中一共展示了Conn.Write方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AppLogs
func AppLogs(ws *websocket.Conn) *httperr.Error {
app := mux.Vars(ws.Request())["app"]
a, err := models.GetApp(app)
if awsError(err) == "ValidationError" {
return httperr.Errorf(404, "no such app: %s", app)
}
if err != nil {
return httperr.Server(err)
}
logs := make(chan []byte)
done := make(chan bool)
a.SubscribeLogs(logs, done)
go signalWsClose(ws, done)
for data := range logs {
ws.Write(data)
}
return nil
}
示例2: keepAlive
func keepAlive(ws *websocket.Conn, quit chan bool) {
c := time.Tick(5 * time.Second)
b := []byte{}
for {
select {
case <-c:
ws.Write(b)
case <-quit:
return
}
}
}
示例3: ServiceLogs
func ServiceLogs(ws *websocket.Conn) *httperr.Error {
service := mux.Vars(ws.Request())["service"]
s, err := models.GetService(service)
if err != nil {
return httperr.Server(err)
}
logs := make(chan []byte)
done := make(chan bool)
s.SubscribeLogs(logs, done)
go signalWsClose(ws, done)
for data := range logs {
ws.Write(data)
}
return nil
}
示例4: scanLines
func scanLines(r io.Reader, ws *websocket.Conn) {
scanner := bufio.NewScanner(r)
for scanner.Scan() {
parts := strings.SplitN(scanner.Text(), "|", 2)
if len(parts) < 2 {
ws.Write([]byte(parts[0] + "\n"))
continue
}
switch parts[0] {
case "manifest":
case "error":
ws.Write([]byte(parts[1] + "\n"))
default:
ws.Write([]byte(parts[1] + "\n"))
}
}
}