Read runtime configuration from datastore.
[kraftakt.git] / app / config.go
diff --git a/app/config.go b/app/config.go
new file mode 100644 (file)
index 0000000..f05a9e6
--- /dev/null
@@ -0,0 +1,28 @@
+package app
+
+import (
+       "context"
+
+       "google.golang.org/appengine/datastore"
+       "google.golang.org/appengine/log"
+)
+
+var Config struct {
+       ProjectNumber string
+
+       FitbitClientID       string
+       FitbitClientSecret   string
+       FitbitSubscriberCode string
+
+       GoogleClientID     string
+       GoogleClientSecret string
+}
+
+func LoadConfig(ctx context.Context) error {
+       key := datastore.NewKey(ctx, "Config", "Production", 0, nil)
+       if err := datastore.Get(ctx, key, &Config); err != nil {
+               log.Errorf(ctx, `datastore.Get("Config", "Production") = %v`, err)
+               return err
+       }
+       return nil
+}