Mercurial > gemma
view auth/opendb.go @ 116:dad6cf39691e
Renamed remaining wamos stuff to gemma.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 26 Jun 2018 16:40:44 +0200 |
parents | a9d3990b083b |
children | bb9120d28950 |
line wrap: on
line source
package auth import ( "database/sql" "fmt" "strings" "gemma.intevation.de/gemma/config" _ "github.com/jackc/pgx/stdlib" ) const driver = "pgx" // dbQuote quotes strings to be able to contain whitespace // and backslashes in database DSN strings. var dbQuote = strings.NewReplacer(`\`, `\\`, `'`, `\'`).Replace // dbDSN creates a data source name suitable for sql.Open on // PostgreSQL databases. func dbDSN(host string, port uint, dbname, user, password string, sslmode string) string { return fmt.Sprintf("host='%s' port=%d dbname='%s' user='%s' password='%s' sslmode='%s'", dbQuote(host), port, dbQuote(dbname), dbQuote(user), dbQuote(password), sslmode) } func opendb(user, password string) (*sql.DB, error) { return sql.Open(driver, dbDSN( config.Config.DBHost, config.Config.DBPort, config.Config.DBName, user, password, config.Config.DBSSLMode)) }