當前位置: 首頁>>代碼示例>>Golang>>正文


Golang websocket.Conn類代碼示例

本文整理匯總了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;未經允許,請勿轉載。