Skip to content

Commit a40abd4

Browse files
support testnet and custom events endpoints (#10)
1 parent 0be4242 commit a40abd4

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

internal/cmd/coinset/events.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cmd
33
import (
44
"encoding/json"
55
"fmt"
6+
"log"
67
"os"
78
"os/signal"
89
"time"
@@ -40,10 +41,15 @@ func runEvents(cmd *cobra.Command, args []string) {
4041
eventType = args[0]
4142
}
4243

43-
c, _, err := websocket.DefaultDialer.Dial("wss://api.coinset.org/ws", nil)
44+
endpoint := fmt.Sprintf("wss://%s/ws", apiHost())
45+
46+
if api != "" {
47+
endpoint = api
48+
}
49+
50+
c, _, err := websocket.DefaultDialer.Dial(endpoint, nil)
4451
if err != nil {
45-
fmt.Println(err)
46-
return
52+
log.Fatal(err.Error())
4753
}
4854
defer c.Close()
4955

internal/cmd/coinset/util.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ func formatHex(str string) string {
3131
return "0x" + str
3232
}
3333

34+
func apiHost() string {
35+
baseUrl, err := url.Parse(apiRoot())
36+
if err != nil {
37+
log.Fatal(err.Error())
38+
}
39+
return baseUrl.Host
40+
}
41+
3442
func apiRoot() string {
3543
if api != "" {
3644
return api

0 commit comments

Comments
 (0)