Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Augustus <[email protected]>
  • Loading branch information
daveaugustus committed May 9, 2024
0 parents commit 83a3002
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
60 changes: 60 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 83a3002

Please sign in to comment.