chore(samples): replace tab for 4 spaces

This commit is contained in:
banasa44
2025-07-23 10:51:03 +02:00
committed by akcodez
parent 2abda7d682
commit 43630fbdca
44 changed files with 5891 additions and 5891 deletions

View File

@@ -7,15 +7,15 @@ package main
// install: go get github.com/gorilla/websocket
import (
"encoding/json"
"flag"
"log"
"net/url"
"os"
"os/signal"
"time"
"encoding/json"
"flag"
"log"
"net/url"
"os"
"os/signal"
"time"
"github.com/gorilla/websocket"
"github.com/gorilla/websocket"
)
// websocket address
@@ -23,75 +23,75 @@ var addr = flag.String("addr", "s.altnet.rippletest.net:51233", "http service ad
// Payload object
type message struct {
Command string `json:"command"`
Accounts []string `json:"accounts"`
Command string `json:"command"`
Accounts []string `json:"accounts"`
}
func main() {
flag.Parse()
log.SetFlags(0)
flag.Parse()
log.SetFlags(0)
var m message
var m message
// check for interrupts and cleanly close the connection
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
// check for interrupts and cleanly close the connection
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt)
u := url.URL{Scheme: "ws", Host: *addr, Path: "/"}
log.Printf("connecting to %s", u.String())
u := url.URL{Scheme: "ws", Host: *addr, Path: "/"}
log.Printf("connecting to %s", u.String())
// make the connection
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil {
log.Fatal("dial:", err)
}
// on exit close
defer c.Close()
// make the connection
c, _, err := websocket.DefaultDialer.Dial(u.String(), nil)
if err != nil {
log.Fatal("dial:", err)
}
// on exit close
defer c.Close()
done := make(chan struct{})
done := make(chan struct{})
// send a subscribe command and a target XRPL account
m.Command = "subscribe"
m.Accounts = append(m.Accounts, "rUCzEr6jrEyMpjhs4wSdQdz4g8Y382NxfM")
// send a subscribe command and a target XRPL account
m.Command = "subscribe"
m.Accounts = append(m.Accounts, "rUCzEr6jrEyMpjhs4wSdQdz4g8Y382NxfM")
// struct to JSON marshalling
msg, _ := json.Marshal(m)
// write to the websocket
err = c.WriteMessage(websocket.TextMessage, []byte(string(msg)))
if err != nil {
log.Println("write:", err)
return
}
// struct to JSON marshalling
msg, _ := json.Marshal(m)
// write to the websocket
err = c.WriteMessage(websocket.TextMessage, []byte(string(msg)))
if err != nil {
log.Println("write:", err)
return
}
// read from the websocket
_, message, err := c.ReadMessage()
if err != nil {
log.Println("read:", err)
return
}
// print the response from the XRP Ledger
log.Printf("recv: %s", message)
// read from the websocket
_, message, err := c.ReadMessage()
if err != nil {
log.Println("read:", err)
return
}
// print the response from the XRP Ledger
log.Printf("recv: %s", message)
// handle interrupt
for {
select {
case <-done:
return
case <-interrupt:
log.Println("interrupt")
// handle interrupt
for {
select {
case <-done:
return
case <-interrupt:
log.Println("interrupt")
// Cleanly close the connection by sending a close message and then
// waiting (with timeout) for the server to close the connection.
err := c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
if err != nil {
log.Println("write close:", err)
return
}
select {
case <-done:
case <-time.After(time.Second):
}
return
}
}
// Cleanly close the connection by sending a close message and then
// waiting (with timeout) for the server to close the connection.
err := c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
if err != nil {
log.Println("write close:", err)
return
}
select {
case <-done:
case <-time.After(time.Second):
}
return
}
}
}