-
Notifications
You must be signed in to change notification settings - Fork 487
/
Copy pathpty.go
46 lines (36 loc) · 753 Bytes
/
pty.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package terminal
import (
"github.com/0xJacky/Nginx-UI/internal/logger"
"github.com/0xJacky/Nginx-UI/internal/pty"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
"net/http"
)
func Pty(c *gin.Context) {
var upGrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool {
return true
},
}
// upgrade http to websocket
ws, err := upGrader.Upgrade(c.Writer, c.Request, nil)
if err != nil {
logger.Error(err)
return
}
defer ws.Close()
p, err := pty.NewPipeLine(ws)
if err != nil {
logger.Error(err)
return
}
defer p.Close()
errorChan := make(chan error, 1)
go p.ReadPtyAndWriteWs(errorChan)
go p.ReadWsAndWritePty(errorChan)
err = <-errorChan
if err != nil {
logger.Error(err)
}
return
}