mirror of
https://github.com/bingohuang/docker-labs.git
synced 2025-10-05 09:53:21 +08:00
Initial commit
This commit is contained in:
36
handlers/exec.go
Normal file
36
handlers/exec.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/net/websocket"
|
||||
|
||||
"github.com/go-zoo/bone"
|
||||
"github.com/xetorthio/play-with-docker/services"
|
||||
)
|
||||
|
||||
// Echo the data received on the WebSocket.
|
||||
func Exec(ws *websocket.Conn) {
|
||||
id := bone.GetValue(ws.Request(), "id")
|
||||
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():
|
||||
}
|
||||
//io.Copy(ws, os.Stdout)
|
||||
//go func() {
|
||||
//io.Copy(*conn, ws)
|
||||
//}()
|
||||
}
|
Reference in New Issue
Block a user