Skip to content
Browse files

Added ConnectByAddr() for that can be connected too using the type ne…

…t.TCPAddr
  • Loading branch information...
1 parent 41b814b commit 60034429b493d95c28256112255dc0f26dd98593 John Mac committed with Jun 17, 2010
Showing with 8 additions and 4 deletions.
  1. +8 −4 mongo/mongo.go
View
12 mongo/mongo.go
@@ -37,8 +37,7 @@ type message interface {
}
type Connection struct {
- host string
- port int
+ addr *net.TCPAddr
conn *net.TCPConn
}
@@ -57,15 +56,20 @@ func Connect(host string, port int) (*Connection, os.Error) {
return nil, err
}
+ return ConnectByAddr(addr)
+}
+
+func ConnectByAddr(addr *net.TCPAddr) (*Connection, os.Error) {
+ // Connects from local host (nil)
conn, err := net.DialTCP("tcp", nil, addr)
if err != nil {
return nil, err
}
- return &Connection{host, port, conn}, nil
+ return &Connection{addr, conn}, nil
}
-/* Closes the conection to the Database. */
+/* Closes the conection to the database. */
func (self *Connection) Close() os.Error {
if err := self.conn.Close(); err != nil {
return err

0 comments on commit 6003442

Please sign in to comment.
Something went wrong with that request. Please try again.