本文整理汇总了Golang中github.com/convox/kernel/Godeps/_workspace/src/golang.org/x/net/websocket.Conn类的典型用法代码示例。如果您正苦于以下问题:Golang Conn类的具体用法?Golang Conn怎么用?Golang Conn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Conn类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: 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
}
}
}
开发者ID:csquared,项目名称:kernel,代码行数:13,代码来源:builds.go
示例2: BuildLogs
func BuildLogs(ws *websocket.Conn) {
defer ws.Close()
log := buildsLogger("logs").Start()
vars := mux.Vars(ws.Request())
id := vars["build"]
log.Success("step=upgrade build=%q", id)
defer ws.Close()
// proxy to docker container logs
// https://docs.docker.com/reference/api/docker_remote_api_v1.19/#get-container-logs
client, err := docker.NewClient("unix:///var/run/docker.sock")
if err != nil {
helpers.Error(log, err)
ws.Write([]byte(fmt.Sprintf("error: %s\n", err)))
return
}
r, w := io.Pipe()
quit := make(chan bool)
go scanLines(r, ws)
go keepAlive(ws, quit)
err = client.Logs(docker.LogsOptions{
Container: fmt.Sprintf("build-%s", id),
Follow: true,
Stdout: true,
Stderr: true,
Tail: "all",
RawTerminal: false,
OutputStream: w,
ErrorStream: w,
})
quit <- true
if err != nil {
helpers.Error(log, err)
ws.Write([]byte(fmt.Sprintf("error: %s\n", err)))
return
}
}
开发者ID:csquared,项目名称:kernel,代码行数:48,代码来源:builds.go
示例3: 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"))
}
}
}
开发者ID:csquared,项目名称:kernel,代码行数:20,代码来源:builds.go
示例4: ProcessRunAttached
func ProcessRunAttached(ws *websocket.Conn) {
defer ws.Close()
log := processesLogger("run.attached").Start()
vars := mux.Vars(ws.Request())
app := vars["app"]
process := vars["process"]
command := ws.Request().Header.Get("Command")
ps, err := models.GetProcess(app, process)
if err != nil {
helpers.Error(log, err)
ws.Write([]byte(fmt.Sprintf("error: %s\n", err)))
return
}
log.Success("step=upgrade app=%q", ps.App)
defer ws.Close()
err = ps.RunAttached(command, ws)
if err != nil {
helpers.Error(log, err)
ws.Write([]byte(fmt.Sprintf("error: %s\n", err)))
return
}
log.Success("step=ended app=%q", ps.App)
}
开发者ID:2opremio,项目名称:kernel,代码行数:32,代码来源:processes.go
注:本文中的github.com/convox/kernel/Godeps/_workspace/src/golang.org/x/net/websocket.Conn类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论