mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-07-15 02:37:27 +08:00
33 lines
547 B
Go
33 lines
547 B
Go
package handlers
|
|
|
|
import (
|
|
"io"
|
|
|
|
"golang.org/x/net/context"
|
|
"golang.org/x/net/websocket"
|
|
|
|
"github.com/franela/play-with-docker/services"
|
|
"github.com/go-zoo/bone"
|
|
)
|
|
|
|
// Echo the data received on the WebSocket.
|
|
func Exec(ws *websocket.Conn) {
|
|
id := bone.GetValue(ws.Request(), "instanceId")
|
|
ctx := context.Background()
|
|
conn, err := services.GetExecConnection(id, ctx)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
defer conn.Close()
|
|
go func() {
|
|
io.Copy(ws, conn.Reader)
|
|
}()
|
|
go func() {
|
|
io.Copy(conn.Conn, ws)
|
|
}()
|
|
select {
|
|
case <-ctx.Done():
|
|
}
|
|
}
|