package main
import (
"bufio"
"fmt"
"io/ioutil"
"log"
"os"
"github.com/gorilla/websocket"
)
const url = "ws:/127.0.0.1:8080/api/vali/v3/websocket/terminal/cluster/123456789/my-system/etcd-12345/etcd"
func main() {
wsURL := url
log.Printf("wsURL: %s\n", wsURL)
ws, _, err := websocket.DefaultDialer.Dial(wsURL, nil)
if err != nil {
fmt.Printf("Dial server error: %s\n", err.Error())
return
}
defer ws.Close()
log.Printf("Dial success")
go func() {
for {
log.Printf("wait data...")
_, r, err := ws.NextReader()
if err != nil {
log.Printf("NextReader error: %s", err.Error())
return
}
data, err := ioutil.ReadAll(r)
log.Printf(string(data))
}
}()
for {
reader := bufio.NewReader(os.Stdin)
bytes, _, err := reader.ReadLine()
if err != nil {
fmt.Printf("ReadLine error: %s\n", err.Error())
return
}
bytes = append(bytes, '\n')
if err := ws.WriteMessage(websocket.TextMessage, bytes); err != nil {
fmt.Printf("WriteMessage to websocket error: %s\n", err.Error())
return
}
}
}