diff --git a/src/github.com/matrix-org/go-neb/config.go b/src/github.com/matrix-org/go-neb/config.go new file mode 100644 index 0000000..c7cf5f8 --- /dev/null +++ b/src/github.com/matrix-org/go-neb/config.go @@ -0,0 +1,12 @@ +package main + +import ( + log "github.com/Sirupsen/logrus" + "github.com/matrix-org/go-neb/database" +) + +func loadFromConfig(db *database.ServiceDB, configFile string) error { + logger := log.WithField("config_file", configFile) + logger.Info("Loading from config file") + return nil +} diff --git a/src/github.com/matrix-org/go-neb/goneb.go b/src/github.com/matrix-org/go-neb/goneb.go index d2c6f11..d1d7e35 100644 --- a/src/github.com/matrix-org/go-neb/goneb.go +++ b/src/github.com/matrix-org/go-neb/goneb.go @@ -31,6 +31,7 @@ func main() { databaseURL := os.Getenv("DATABASE_URL") baseURL := os.Getenv("BASE_URL") logDir := os.Getenv("LOG_DIR") + configYAML := os.Getenv("CONFIG_FILE") if logDir != "" { log.AddHook(dugong.NewFSHook( @@ -41,8 +42,8 @@ func main() { } log.Infof( - "Go-NEB (BIND_ADDRESS=%s DATABASE_TYPE=%s DATABASE_URL=%s BASE_URL=%s LOG_DIR=%s)", - bindAddress, databaseType, databaseURL, baseURL, logDir, + "Go-NEB (BIND_ADDRESS=%s DATABASE_TYPE=%s DATABASE_URL=%s BASE_URL=%s LOG_DIR=%s CONFIG_FILE=%s)", + bindAddress, databaseType, databaseURL, baseURL, logDir, configYAML, ) err := types.BaseURL(baseURL) @@ -50,12 +51,23 @@ func main() { log.WithError(err).Panic("Failed to get base url") } + if configYAML != "" { + databaseType = "sqlite3" + databaseURL = ":memory:?_busy_timeout=5000" + } + db, err := database.Open(databaseType, databaseURL) if err != nil { log.WithError(err).Panic("Failed to open database") } database.SetServiceDB(db) + if configYAML != "" { + if err := loadFromConfig(db, configYAML); err != nil { + log.WithError(err).WithField("config_file", configYAML).Panic("Failed to load config file") + } + } + clients := clients.New(db) if err := clients.Start(); err != nil { log.WithError(err).Panic("Failed to start up clients")