Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Cmd = &cobra.Command{ Use: "subscribe", Short: "subscribe", Run: func(cmd *cobra.Command, args []string) { interrupt := make(chan os.Signal, 1) signal.Notify(interrupt, os.Interrupt) u := url.URL{Scheme: "ws", Host: host, Path: "/ws/subscribe"} c, _, err := websocket.DefaultDialer.Dial(u.String(), nil) if err != nil { logrus.Error("dial:", err) return } defer c.Close() done := make(chan struct{}) go func() { defer close(done) for { _, message, err := c.ReadMessage() if err != nil { logrus.Info("read:", err) return } fmt.Println(string(message)) } }() ticker := time.NewTicker(time.Second) defer ticker.Stop() for { select { case <-done: return case t := <-ticker.C: err := c.WriteMessage(websocket.TextMessage, []byte(t.String())) if err != nil { logrus.Info("write:", err) return } case <-interrupt: logrus.Debug("interrupt") err := c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, "")) if err != nil { logrus.Println("write close:", err) return } select { case <-done: case <-time.After(time.Second): } return } } }, }
Cmd is the command for the cli tool
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.