Add function exitWithMessage to terminate program

This commit is contained in:
Dan Sosedoff 2014-10-11 22:33:59 -05:00
parent 8dcb66d58c
commit ba74d8193c

17
main.go
View File

@ -20,6 +20,11 @@ var options struct {
var dbClient *Client var dbClient *Client
func exitWithMessage(message string) {
fmt.Println("Error:", message)
os.Exit(1)
}
func getConnectionString() string { func getConnectionString() string {
if options.Url != "" { if options.Url != "" {
return options.Url return options.Url
@ -36,27 +41,23 @@ func initClient() {
client, err := NewClient() client, err := NewClient()
if err != nil { if err != nil {
fmt.Println("Error:", err) exitWithMessage(err.Error())
os.Exit(1)
} }
_, err = client.Query(SQL_INFO) _, err = client.Query(SQL_INFO)
if err != nil { if err != nil {
fmt.Println("Error:", err) exitWithMessage(err.Error())
os.Exit(1)
} }
tables, err := client.Tables() tables, err := client.Tables()
if err != nil { if err != nil {
fmt.Println("Error:", err) exitWithMessage(err.Error())
os.Exit(1)
} }
if len(tables) == 0 { if len(tables) == 0 {
fmt.Println("Error: Database does not have any tables") exitWithMessage("Database does not have any tables")
os.Exit(1)
} }
dbClient = client dbClient = client