tempestas

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

commit cbfa2fefb64ba825ff6abc72b364b7126f708f8a
parent 0d6c3e32ae774ba0a91ae1a76df13f0b280f03a7
Author: Chris Bracken <chris@bracken.jp>
Date:   Thu, 11 Nov 2021 16:51:14 -0800

Allow user-specified port on which to start server

The HTTP server is now customisable via the TEMPESTAS_ADDR environment
variable, specified as:

    export TEMPESTAS_ADDR=":8080"

Diffstat:
MREADME.md | 5+++++
Mmain.go | 8++++++--
2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md @@ -15,4 +15,9 @@ To build and run the binary: export TEMPESTAS_PASS=password ./tempestas +By default, the HTTP server will be started on port 8080. To specify a different +port set the `TEMPESTAS_ADDR` environment variable. For example: + + export TEMPESTAS_ADDR=":9090" + [sc]: https://sensor.community diff --git a/main.go b/main.go @@ -18,7 +18,11 @@ func main() { ds := storage.ConnectPostgres(dbname, dbuser, dbpass) defer ds.Close() - fmt.Println("Waiting for requests") + addr := os.Getenv("TEMPESTAS_ADDR") + if addr == "" { + addr = ":8080" + } + fmt.Println("Waiting for requests at " + addr) s := http.CreateServer(ds) - log.Fatal(s.ListenAndServe(":8080")) + log.Fatal(s.ListenAndServe(addr)) }