summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/websocket.go34
1 files changed, 33 insertions, 1 deletions
diff --git a/tools/websocket.go b/tools/websocket.go
index c882ce2..b956ee8 100644
--- a/tools/websocket.go
+++ b/tools/websocket.go
@@ -9,10 +9,12 @@
package main
import (
+ "encoding/json"
"log"
"net/url"
"os"
"os/signal"
+ "strings"
"syscall"
"github.com/gorilla/websocket"
@@ -83,8 +85,38 @@ func getConfig(c *websocket.Conn) {
}
}
`
- err := c.WriteMessage(websocket.TextMessage, []byte(request))
+
+ tx(c, request)
+}
+
+func tx(c *websocket.Conn, d string) {
+ input := []byte(d)
+
+ var parsed any
+
+ err := json.Unmarshal(input, &parsed)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ pretty, err := json.MarshalIndent(parsed, "", " ")
if err != nil {
log.Fatal(err)
}
+
+ log.Println(quote(string(pretty), "> "))
+ err = c.WriteMessage(websocket.TextMessage, pretty)
+ if err != nil {
+ log.Fatal(err)
+ }
+}
+
+func quote(input string, quotation string) string {
+ lines := strings.Split(input, "\n")
+
+ for i, line := range lines {
+ lines[i] = quotation + line
+ }
+
+ return strings.Join(lines, "\n")
}