mirror of
https://github.com/go-i2p/goSam.git
synced 2025-07-13 14:18:25 -04:00
NewClient now opens the TCP socket itself
This commit is contained in:
17
client.go
17
client.go
@ -4,6 +4,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
@ -13,11 +14,19 @@ type Client struct {
|
|||||||
toSam *bufio.Writer
|
toSam *bufio.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClient(samConn io.ReadWriteCloser) (*Client, error) {
|
func NewDefaultClient() (*Client, error) {
|
||||||
|
return NewClient("localhost:7656")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewClient(addr string) (*Client, error) {
|
||||||
|
conn, err := net.Dial("tcp", addr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
c := &Client{
|
c := &Client{
|
||||||
samConn: samConn,
|
samConn: conn,
|
||||||
fromSam: bufio.NewReader(samConn),
|
fromSam: bufio.NewReader(conn),
|
||||||
toSam: bufio.NewWriter(samConn),
|
toSam: bufio.NewWriter(conn),
|
||||||
}
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package goSam
|
package goSam
|
||||||
|
|
||||||
import (
|
import "testing"
|
||||||
"net"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
client *Client
|
client *Client
|
||||||
@ -13,12 +10,7 @@ func setup() {
|
|||||||
var err error
|
var err error
|
||||||
|
|
||||||
// these tests expect a running SAM brige on this address
|
// these tests expect a running SAM brige on this address
|
||||||
conn, err := net.Dial("tcp", "localhost:7656")
|
client, err = NewDefaultClient()
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err = NewClient(conn)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user