Skip to content

Commit 98b6286

Browse files
Merge pull request #10 from byoungdale/byoungdale/update/wsserver-api-client
added wsserver flag to call-api-client tool
2 parents a6b09cc + 1774d4a commit 98b6286

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

cmd/call-api-client/main.go

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,22 @@ import (
2626
"os/signal"
2727
"time"
2828

29+
"github.com/OpenSIPS/call-api/internal/jsonrpc"
30+
"github.com/OpenSIPS/call-api/pkg/config"
2931
"github.com/gorilla/websocket"
3032
"github.com/sirupsen/logrus"
31-
"github.com/OpenSIPS/call-api/pkg/config"
32-
"github.com/OpenSIPS/call-api/internal/jsonrpc"
3333
)
3434

3535
func usage(prog string) {
3636
logrus.Fatalf("Usage: %s jsonrpc_method [jsonrpc_arguments]", prog)
3737
}
3838

39-
func ParseClientArgs() (string, string, interface{}, string) {
40-
var method, params, id string
39+
func ParseClientArgs() (string, int, string, string, interface{}, string) {
40+
var wsServer, method, params, id string
41+
var wsPort int
4142

43+
flag.StringVar(&wsServer, "wshost", "", "The websocket host to connect to")
44+
flag.IntVar(&wsPort, "wsport", 0, "The websocket port to connect to")
4245
flag.StringVar(&method, "method", "", "JSON-RPC method")
4346
flag.StringVar(&params, "params", "", "JSON-RPC params")
4447
flag.StringVar(&id, "id", "", "JSON-RPC id")
@@ -62,7 +65,7 @@ func ParseClientArgs() (string, string, interface{}, string) {
6265
}
6366
}
6467

65-
return cfgPath, method, v, id
68+
return wsServer, wsPort, cfgPath, method, v, id
6669
}
6770

6871
func closeWSConnection(c *websocket.Conn) {
@@ -79,14 +82,22 @@ func closeWSConnection(c *websocket.Conn) {
7982

8083
func main() {
8184
// parse cmdline args
82-
cfgPath, method, params, id := ParseClientArgs()
85+
wsServer, wsPort, cfgPath, method, params, id := ParseClientArgs()
8386

8487
// read configuration
8588
cfg, err := config.NewConfig(cfgPath)
8689
if err != nil {
8790
logrus.Fatal(err)
8891
}
8992

93+
if wsServer == "" {
94+
wsServer = cfg.WSServer.Host
95+
}
96+
97+
if wsPort == 0 {
98+
wsPort = cfg.WSServer.Port
99+
}
100+
90101
// prepare logging
91102
logfile, err := config.InitLogging(cfg)
92103
if err != nil {
@@ -99,7 +110,7 @@ func main() {
99110
interrupt := make(chan os.Signal, 1)
100111
signal.Notify(interrupt, os.Interrupt)
101112

102-
api_hostport := fmt.Sprintf("%s:%d", cfg.WSServer.Host, cfg.WSServer.Port)
113+
api_hostport := fmt.Sprintf("%s:%d", wsServer, wsPort)
103114
u := url.URL{Scheme: "ws", Host: api_hostport, Path: cfg.WSServer.Path}
104115
logrus.Printf("connecting to %s", u.String())
105116

@@ -128,7 +139,7 @@ func main() {
128139

129140
err = json.Unmarshal(message, &v)
130141
if err != nil {
131-
logrus.Println("failed to parse JSON reply: %s", err)
142+
logrus.Printf("failed to parse JSON reply: %s", err)
132143
return
133144
}
134145

0 commit comments

Comments
 (0)