Skip to content

Commit 9587606

Browse files
committed
error cleanup, use net.JoinHostPort
1 parent 6699575 commit 9587606

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

client.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"bufio"
1111
"fmt"
1212
"io"
13+
"net"
14+
"strconv"
1315
"time"
1416
)
1517

@@ -27,14 +29,17 @@ type Client struct {
2729
// EstablishConnection - Will attempt to establish connection against freeswitch and create new SocketConnection
2830
func (c *Client) EstablishConnection() error {
2931
conn, err := c.Dial(c.Proto, c.Addr, time.Duration(c.Timeout*int(time.Second)))
32+
if err != nil {
33+
return err
34+
}
3035

3136
c.SocketConnection = SocketConnection{
3237
Conn: conn,
3338
err: make(chan error),
3439
m: make(chan *Message),
3540
}
3641

37-
return err
42+
return nil
3843
}
3944

4045
// Authenticate - Method used to authenticate client against freeswitch. In case of any errors durring so
@@ -85,7 +90,7 @@ func (c *Client) Authenticate() error {
8590
func NewClient(host string, port uint, passwd string, timeout int) (*Client, error) {
8691
client := Client{
8792
Proto: "tcp", // Let me know if you ever need this open up lol
88-
Addr: fmt.Sprintf("%s:%d", host, port),
93+
Addr: net.JoinHostPort(host, strconv.Itoa(int(port))),
8994
Passwd: passwd,
9095
Timeout: timeout,
9196
}

0 commit comments

Comments
 (0)