Add --pass flat to specify user password, closes #18, via @waltonseymour

This commit is contained in:
Dan Sosedoff 2014-10-28 22:22:17 -05:00
parent ee4883b448
commit 01666c8f3d
2 changed files with 9 additions and 1 deletions

View File

@ -74,6 +74,7 @@ Application Options:
--host= Server hostname or IP (localhost)
--port= Server port (5432)
--user= Database user (postgres)
--pass= Password for user
--db= Database name (postgres)
--ssl= SSL option (disable)
--listen= HTTP server listen port (8080)

View File

@ -19,6 +19,7 @@ var options struct {
Host string `long:"host" description:"Server hostname or IP" default:"localhost"`
Port int `long:"port" description:"Server port" default:"5432"`
User string `long:"user" description:"Database user" default:"postgres"`
Pass string `long:"pass" description:"Password for user"`
DbName string `long:"db" description:"Database name" default:"postgres"`
Ssl string `long:"ssl" description:"SSL option" default:"disable"`
HttpPort uint `long:"listen" description:"HTTP server listen port" default:"8080"`
@ -36,12 +37,18 @@ func getConnectionString() string {
return options.Url
}
return fmt.Sprintf(
str := fmt.Sprintf(
"host=%s port=%d user=%s dbname=%s sslmode=%s",
options.Host, options.Port,
options.User, options.DbName,
options.Ssl,
)
if options.Pass != "" {
str += fmt.Sprintf(" password=%s", options.Pass)
}
return str
}
func initClient() {