bot.go 470 B

1234567891011121314151617181920212223242526
  1. package api
  2. import (
  3. "fmt"
  4. "log"
  5. "net/url"
  6. "github.com/gorilla/websocket"
  7. )
  8. type WsBot struct {
  9. Wsconn *websocket.Conn
  10. }
  11. func WebsocketBot(host string, port string, path string) WsBot {
  12. wsurl := url.URL{Scheme: "ws", Host: host + ":" + port, Path: path}
  13. conn, _, err := websocket.DefaultDialer.Dial(wsurl.String(), nil)
  14. if err != nil {
  15. log.Fatal("Failed to connect to WebSocket server:", err)
  16. }
  17. return WsBot{conn}
  18. }
  19. func Test() {
  20. fmt.Println("test")
  21. }