tempestas

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

commit c4d2dfc39b1c1dd05b106296fb7e5026cfb67b27
parent d5827970ba6882c8db6c34cdebc0501d2b74ebba
Author: Chris Bracken <chris@bracken.jp>
Date:   Mon, 11 Apr 2022 17:23:21 -0700

Use flags for tempestas options

This eliminates the use of environment variables for options and
replaces them with command-line flags.

Diffstat:
Mmain.go | 23+++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/main.go b/main.go @@ -1,9 +1,9 @@ package main import ( + "flag" "fmt" "log" - "os" "git.bracken.jp/tempestas/http" "git.bracken.jp/tempestas/storage" @@ -11,18 +11,17 @@ import ( ) func main() { - fmt.Println("Initializing database") - dbname := os.Getenv("TEMPESTAS_DB") - dbuser := os.Getenv("TEMPESTAS_USER") - dbpass := os.Getenv("TEMPESTAS_PASS") - ds := storage.ConnectPostgres(dbname, dbuser, dbpass) + dbname := flag.String("db", "tempestas", "the database name") + dbuser := flag.String("user", "tempestas", "the database user") + dbpass := flag.String("password", "", "the database password") + addr := flag.String("address", ":8080", "HTTP service host:port") + flag.Parse() + + fmt.Println("Connecting to database") + ds := storage.ConnectPostgres(*dbname, *dbuser, *dbpass) defer ds.Close() - addr := os.Getenv("TEMPESTAS_ADDR") - if addr == "" { - addr = ":8080" - } - fmt.Println("Waiting for requests at " + addr) + fmt.Println("Waiting for requests at " + *addr) s := http.CreateServer(ds, "static") - log.Fatal(s.ListenAndServe(addr)) + log.Fatal(s.ListenAndServe(*addr)) }