Add API method to connect to server with given url

This commit is contained in:
Dan Sosedoff
2014-10-31 22:37:58 -05:00
parent 5a2c13e6c4
commit 7ac9bee098
3 changed files with 41 additions and 0 deletions

View File

@@ -32,6 +32,16 @@ func NewClient() (*Client, error) {
return &Client{db: db}, nil
}
func NewClientFromUrl(url string) (*Client, error) {
db, err := sqlx.Open("postgres", url)
if err != nil {
return nil, err
}
return &Client{db: db}, nil
}
func (client *Client) Test() error {
return client.db.Ping()
}