2014-02-10 21:01:55 +01:00
|
|
|
package goSam
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2014-02-11 14:48:13 +01:00
|
|
|
// Implements the net.Dial function can be used for http.Transport
|
2014-02-10 21:01:55 +01:00
|
|
|
func (c *Client) Dial(network, addr string) (net.Conn, error) {
|
2014-02-11 13:10:24 +01:00
|
|
|
portIdx := strings.Index(addr, ":")
|
|
|
|
if portIdx >= 0 {
|
|
|
|
addr = addr[:portIdx]
|
|
|
|
}
|
2014-02-10 21:01:55 +01:00
|
|
|
addr, err := c.Lookup(addr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-02-11 14:48:13 +01:00
|
|
|
id, _, err := c.CreateStreamSession("")
|
2014-02-10 21:01:55 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
newC, err := NewDefaultClient()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-02-11 14:08:52 +01:00
|
|
|
if c.verbose {
|
|
|
|
newC.ToggleVerbose()
|
|
|
|
}
|
2014-02-10 21:01:55 +01:00
|
|
|
|
2014-02-11 14:08:52 +01:00
|
|
|
err = newC.StreamConnect(id, addr)
|
|
|
|
if err != nil {
|
2014-02-10 21:01:55 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-02-11 14:08:52 +01:00
|
|
|
return newC.SamConn, nil
|
2014-02-10 21:01:55 +01:00
|
|
|
}
|