From 9b90391793ec158e55f8707ecb2cd0e73f39bd83 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 16 Nov 2019 14:07:17 +0100 Subject: [PATCH] Let tools use PG* env variables If options are not specified in the connection string, the postgres driver will pick the corresponding environment variables. Therefore this commit changes the default connection string to the empty string. This commit fixes #70. --- c14h/db_port.go | 2 +- c14h/main.go | 2 +- data/data.go | 5 ++++- yarpnarp/main.go | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/c14h/db_port.go b/c14h/db_port.go index 9ffee38..59f6e9b 100644 --- a/c14h/db_port.go +++ b/c14h/db_port.go @@ -15,7 +15,7 @@ import ( var ( db *sql.DB driver = flag.String("driver", "postgres", "The database driver to use") - connect = flag.String("connect", "dbname=nnev host=/var/run/postgresql sslmode=disable", "The connection string to use") + connect = flag.String("connect", "", "The connection string to use") ) func openDB() (err error) { diff --git a/c14h/main.go b/c14h/main.go index d05e113..ec8f7ba 100644 --- a/c14h/main.go +++ b/c14h/main.go @@ -21,7 +21,7 @@ import ( var ( addr = flag.String("listen", "0.0.0.0:6725", "The address to listen on") driver = flag.String("driver", "postgres", "The database driver to use") - connect = flag.String("connect", "dbname=nnev host=/var/run/postgresql sslmode=disable", "The connection string to use") + connect = flag.String("connect", "", "The connection string to use") gettpl = flag.String("template", "/var/www/www.noname-ev.de/edit_c14.html", "The template to serve for editing c¼") hook = flag.String("hook", "", "A hook to run on every change") diff --git a/data/data.go b/data/data.go index ad0e4e6..95bd002 100644 --- a/data/data.go +++ b/data/data.go @@ -14,7 +14,10 @@ import ( var ( driver = flag.String("driver", "postgres", "Der benutzte sql-Treiber") - connect = flag.String("connect", "dbname=nnev user=anon host=/var/run/postgresql sslmode=disable", "Die Verbindungsspezifikation") + + // If the connection string is empty, the postgres driver will extract the + // config out of environment variables (PGHOST, PGUSER, PGDATABASE, ...). + connect = flag.String("connect", "", "Die Verbindungsspezifikation") ) // OpenDB opens a connection to the database with parameters derived from flags. diff --git a/yarpnarp/main.go b/yarpnarp/main.go index dde27c4..d006c42 100644 --- a/yarpnarp/main.go +++ b/yarpnarp/main.go @@ -19,7 +19,7 @@ import ( var ( addr = flag.String("listen", "0.0.0.0:5417", "The address to listen on") driver = flag.String("driver", "postgres", "The database driver to use") - connect = flag.String("connect", "dbname=nnev host=/var/run/postgresql sslmode=disable", "The connection string to use") + connect = flag.String("connect", "", "The connection string to use") gettpl = flag.String("template", "/var/www/www.noname-ev.de/yarpnarp.html", "The template to serve for editing zusagen") hook = flag.String("hook", "", "A hook to run on every change")