Skip to content

Instantly share code, notes, and snippets.

@benhenryhunter
Created August 25, 2023 15:09
Show Gist options
  • Save benhenryhunter/19c3cf691642214f34ea9a4f08974c88 to your computer and use it in GitHub Desktop.
Save benhenryhunter/19c3cf691642214f34ea9a4f08974c88 to your computer and use it in GitHub Desktop.
websocket with blxr
package main
import (
"fmt"
"net/http"
"github.com/gorilla/websocket"
)
func main() {
header := http.Header{}
header.Set("Authorization", "<YOUR-AUTHORIZATION-HEADER>")
wsURL := fmt.Sprintf("ws://bloxroute.max-profit.blxrbdn.com/blxr/ws")
conn, _, err := websocket.DefaultDialer.Dial(wsURL, header)
if err != nil {
fmt.Println("Could not connect to relay websocket", "url", wsURL, "err", err)
// return conn, err
} else {
fmt.Println("connected")
}
if err := conn.WriteJSON(map[string]interface{}{"yo": "yo"}); err != nil {
fmt.Println("error writing json", err)
} else {
_, b, err := conn.ReadMessage()
if err != nil {
fmt.Println("error reading message", err)
} else {
fmt.Println(string(b))
}
}
// return conn, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment