Print server connection string in debug mode
This commit is contained in:
parent
52c6e599f7
commit
5b073c4978
12
client.go
12
client.go
@ -10,8 +10,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
db *sqlx.DB
|
db *sqlx.DB
|
||||||
history []string
|
history []string
|
||||||
|
connectionString string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Row []interface{}
|
type Row []interface{}
|
||||||
@ -22,13 +23,14 @@ type Result struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewClient() (*Client, error) {
|
func NewClient() (*Client, error) {
|
||||||
db, err := sqlx.Open("postgres", getConnectionString())
|
str := getConnectionString()
|
||||||
|
db, err := sqlx.Open("postgres", str)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Client{db: db}, nil
|
return &Client{db: db, connectionString: str}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewClientFromUrl(url string) (*Client, error) {
|
func NewClientFromUrl(url string) (*Client, error) {
|
||||||
@ -38,7 +40,7 @@ func NewClientFromUrl(url string) (*Client, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Client{db: db}, nil
|
return &Client{db: db, connectionString: url}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (client *Client) Test() error {
|
func (client *Client) Test() error {
|
||||||
|
4
main.go
4
main.go
@ -107,6 +107,10 @@ func initClient() {
|
|||||||
exitWithMessage(err.Error())
|
exitWithMessage(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options.Debug {
|
||||||
|
fmt.Println("Server connection string:", client.connectionString)
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println("Connecting to server...")
|
fmt.Println("Connecting to server...")
|
||||||
err = client.Test()
|
err = client.Test()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user