tempestas

A REST API for processing sensor.community data
git clone https://git.bracken.jp/tempestas.git
Log | Files | Refs | README | LICENSE

commit c3e836b084fe6e56f6a3ca3f2355e7e21dc36b1d
parent a5f244a207e079f21d612e14f1952ef7e2d979b9
Author: Chris Bracken <chris@bracken.jp>
Date:   Thu, 11 Nov 2021 09:16:31 -0800

Use environment variables for DB setup

Database connection information is now expected to be set in the
following environment variables:

* TEMPESTAS_DB:   database name
* TEMPESTAS_USER: database username to connect as
* TEMPESTAS_PASS: password for the user specified by $TEMPESTAS_USER

Diffstat:
Mmain.go | 6++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/main.go b/main.go @@ -7,6 +7,7 @@ import ( "io" "log" "net/http" + "os" "time" "git.bracken.jp/tempestas/airrohr" @@ -16,9 +17,6 @@ import ( ) const ( - DB_USER = "tempestas" - DB_PASSWORD = "<SET_PASSWORD_HERE>" // TODO: read from file/env - DB_NAME = "tempestas" INSERT_REPORT = "INSERT INTO " + "sensor_data(sensor_id, sw_version, reading_time, reading_type, reading_value) " + "VALUES($1, $2, $3, $4, $5)" @@ -29,7 +27,7 @@ var ( ) func setupDB() *sql.DB { - dbinfo := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=disable", DB_USER, DB_PASSWORD, DB_NAME) + dbinfo := os.ExpandEnv("user=$TEMPESTAS_USER password=$TEMPESTAS_PASS dbname=$TEMPESTAS_DB sslmode=disable") db, err := sql.Open("postgres", dbinfo) if err != nil { panic("Error connecting to database")