-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Dave Augustus <[email protected]>
- Loading branch information
0 parents
commit 83a3002
Showing
3 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |