32 lines
471 B
Go
32 lines
471 B
Go
package rethink
|
|
|
|
import (
|
|
"net/url"
|
|
|
|
r "gopkg.in/rethinkdb/rethinkdb-go.v6"
|
|
)
|
|
|
|
func GetSession(dbURL string) (*r.Session, error) {
|
|
r.SetTags("rethinkdb", "json")
|
|
|
|
u, err := url.Parse(dbURL)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
pw, _ := u.User.Password()
|
|
db := u.Path[1:]
|
|
|
|
session, err := r.Connect(r.ConnectOpts{
|
|
Address: u.Host,
|
|
Database: db,
|
|
Username: u.User.Username(),
|
|
Password: pw,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return session, nil
|
|
}
|