commit 3cac0f67738609e42ea089db547f6629c361225b
parent 71baa5525b95443682bead998b304241cc3b7245
Author: Chris Bracken <chris@bracken.jp>
Date: Tue, 12 Apr 2022 13:31:28 -0700
Support -devdb option
Adds a -devdb option that connects the user to a NullDataStore instance
rather than a postgres database. Simplifies testing on systems that
don't have a database to connect to.
Diffstat:
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
@@ -27,5 +27,6 @@ Options:
-password the database password (default: '')
-address the host:port on which to host the service (default: ':8080')
-assets the HTTP asset directory (default: '/usr/local/share/tempestas/www')
+ -devdb use an empty database for serving up UI code only
[sc]: https://sensor.community
diff --git a/main.go b/main.go
@@ -14,12 +14,19 @@ func main() {
dbname := flag.String("db", "tempestas", "the database name")
dbuser := flag.String("user", "tempestas", "the database user")
dbpass := flag.String("password", "", "the database password")
+ devdb := flag.Bool("devdb", false, "whether to use developer-mode database")
addr := flag.String("address", ":8080", "HTTP service host:port")
assetDir := flag.String("assets", "/usr/local/share/tempestas/www", "HTTP asset directory")
flag.Parse()
- fmt.Println("Connecting to database")
- ds := storage.ConnectPostgres(*dbname, *dbuser, *dbpass)
+ var ds storage.DataStore
+ if *devdb {
+ fmt.Println("Using null database for development")
+ ds = storage.ConnectNull()
+ } else {
+ fmt.Println("Connecting to database")
+ ds = storage.ConnectPostgres(*dbname, *dbuser, *dbpass)
+ }
defer ds.Close()
fmt.Println("Waiting for requests at " + *addr)