11package gorethink
22
33import (
4- "code.google.com/p/goprotobuf/proto"
5- p "github.com/dancannon/gorethink/ql2"
64 "sync/atomic"
75 "time"
6+
7+ "code.google.com/p/goprotobuf/proto"
8+ p "github.com/dancannon/gorethink/ql2"
89)
910
1011type Session struct {
@@ -64,6 +65,21 @@ func newSession(args map[string]interface{}) *Session {
6465 return s
6566}
6667
68+ type ConnectOpts struct {
69+ Token int64 `gorethink:"token,omitempty"`
70+ Address string `gorethink:"address,omitempty"`
71+ Database string `gorethink:"database,omitempty"`
72+ Timeout time.Duration `gorethink:"timeout,omitempty"`
73+ AuthKey string `gorethink:"authkey,omitempty"`
74+ MaxIdle int `gorethink:"max_idle,omitempty"`
75+ MaxActive int `gorethink:"max_active,omitempty"`
76+ IdleTimeout time.Duration `gorethink:"idle_timeout,omitempty"`
77+ }
78+
79+ func (o * ConnectOpts ) toMap () map [string ]interface {} {
80+ return optArgsToMap (o )
81+ }
82+
6783// Connect creates a new database session.
6884//
6985// Supported arguments include token, address, database, timeout, authkey,
@@ -76,13 +92,13 @@ func newSession(args map[string]interface{}) *Session {
7692// Basic connection example:
7793//
7894// var session *r.Session
79- // session, err := r.Connect(map[string]interface{} {
80- // "address" : "localhost:28015",
81- // "database" : "test",
82- // "authkey" : "14daak1cad13dj",
95+ // session, err := r.Connect(r.ConncetOpts {
96+ // Address : "localhost:28015",
97+ // Database : "test",
98+ // AuthKey : "14daak1cad13dj",
8399// })
84- func Connect (args map [ string ] interface {} ) (* Session , error ) {
85- s := newSession (args )
100+ func Connect (args ConnectOpts ) (* Session , error ) {
101+ s := newSession (args . toMap () )
86102 err := s .Reconnect ()
87103
88104 return s , err
0 commit comments