Print server connection string in debug mode

This commit is contained in:
Dan Sosedoff 2014-12-06 12:44:56 -06:00
parent 52c6e599f7
commit 5b073c4978
2 changed files with 11 additions and 5 deletions

View File

@ -10,8 +10,9 @@ import (
)
type Client struct {
db *sqlx.DB
history []string
db *sqlx.DB
history []string
connectionString string
}
type Row []interface{}
@ -22,13 +23,14 @@ type Result struct {
}
func NewClient() (*Client, error) {
db, err := sqlx.Open("postgres", getConnectionString())
str := getConnectionString()
db, err := sqlx.Open("postgres", str)
if err != nil {
return nil, err
}
return &Client{db: db}, nil
return &Client{db: db, connectionString: str}, nil
}
func NewClientFromUrl(url string) (*Client, error) {
@ -38,7 +40,7 @@ func NewClientFromUrl(url string) (*Client, error) {
return nil, err
}
return &Client{db: db}, nil
return &Client{db: db, connectionString: url}, nil
}
func (client *Client) Test() error {

View File

@ -107,6 +107,10 @@ func initClient() {
exitWithMessage(err.Error())
}
if options.Debug {
fmt.Println("Server connection string:", client.connectionString)
}
fmt.Println("Connecting to server...")
err = client.Test()
if err != nil {