From 83a3002e56237c1ffd5ee1b984f80d4dd5c152ea Mon Sep 17 00:00:00 2001 From: Dave Augustus Date: Thu, 9 May 2024 12:20:51 +0530 Subject: [PATCH] Initial commit Signed-off-by: Dave Augustus --- go.mod | 7 +++++++ go.sum | 4 ++++ main.go | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 go.mod create mode 100644 go.sum create mode 100644 main.go diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..4320c9c --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module github.com/daveaugustus/wscli + +go 1.21.7 + +require github.com/gorilla/websocket v1.5.1 + +require golang.org/x/net v0.17.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..272772f --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY= +github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY= +golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= +golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= diff --git a/main.go b/main.go new file mode 100644 index 0000000..9f918b5 --- /dev/null +++ b/main.go @@ -0,0 +1,60 @@ +package main + +import ( + "fmt" + "log" + "net/http" + + "github.com/gorilla/websocket" +) + +func main() { + // Replace with the actual websocket server URL + u := "wss://localhost:8080/api/v1/blog/draft/6564321" + + headers := http.Header{} + headers.Set("Authorization", "Bearer ajd123bnsdjbcbbdbfrb2e89we89cksdbcdsbcbd") + + // Connect to the websocket server + conn, _, err := websocket.DefaultDialer.Dial(u, headers) + if err != nil { + log.Fatal("dial:", err) + } + defer conn.Close() + + fmt.Println("Connected to the websocket server") + + // Define the message to send + message := ` + { + "time": 1278687357, + "blocks": [ + { + "id": "mhTl6ghSkV", + "type": "paragraph", + "data": { + "text": "Hey. Meet the new Editor. On this picture you can see it in action. Then, try a demo 🤓" + }, + "author": "John", + "time": 17107371588 + } + ] + } + ` + + // Send the message + err = conn.WriteMessage(websocket.TextMessage, []byte(message)) + if err != nil { + log.Println("write:", err) + return + } + + // Read any incoming messages (optional) + _, msg, err := conn.ReadMessage() + if err != nil { + log.Println("read:", err) + return + } + + fmt.Printf("Received from server: %s\n", msg) +}