Browse Source

Add stub config file loader

pull/98/head
Kegan Dougal 8 years ago
parent
commit
f4033d1745
  1. 12
      src/github.com/matrix-org/go-neb/config.go
  2. 16
      src/github.com/matrix-org/go-neb/goneb.go

12
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
}

16
src/github.com/matrix-org/go-neb/goneb.go

@ -31,6 +31,7 @@ func main() {
databaseURL := os.Getenv("DATABASE_URL") databaseURL := os.Getenv("DATABASE_URL")
baseURL := os.Getenv("BASE_URL") baseURL := os.Getenv("BASE_URL")
logDir := os.Getenv("LOG_DIR") logDir := os.Getenv("LOG_DIR")
configYAML := os.Getenv("CONFIG_FILE")
if logDir != "" { if logDir != "" {
log.AddHook(dugong.NewFSHook( log.AddHook(dugong.NewFSHook(
@ -41,8 +42,8 @@ func main() {
} }
log.Infof( 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) err := types.BaseURL(baseURL)
@ -50,12 +51,23 @@ func main() {
log.WithError(err).Panic("Failed to get base url") log.WithError(err).Panic("Failed to get base url")
} }
if configYAML != "" {
databaseType = "sqlite3"
databaseURL = ":memory:?_busy_timeout=5000"
}
db, err := database.Open(databaseType, databaseURL) db, err := database.Open(databaseType, databaseURL)
if err != nil { if err != nil {
log.WithError(err).Panic("Failed to open database") log.WithError(err).Panic("Failed to open database")
} }
database.SetServiceDB(db) 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) clients := clients.New(db)
if err := clients.Start(); err != nil { if err := clients.Start(); err != nil {
log.WithError(err).Panic("Failed to start up clients") log.WithError(err).Panic("Failed to start up clients")

Loading…
Cancel
Save