This commit is contained in:
Pedro Nasser
2016-08-01 19:23:31 -03:00
parent f9f1ffaac5
commit dfc4be9861
25 changed files with 137 additions and 160 deletions

31
main.go
View File

@@ -8,24 +8,45 @@ For keeping a minimum running, perhaps when doing a routing table update, if des
package main
import (
"fmt"
"os"
"strings"
log "github.com/Sirupsen/logrus"
"github.com/iron-io/functions/api/datastore"
"github.com/iron-io/functions/api/models"
"github.com/iron-io/functions/api/server"
"github.com/iron-io/titan/common"
"github.com/spf13/viper"
)
func main() {
config := &models.Config{}
config.DatabaseURL = os.Getenv("DB")
config.API = os.Getenv("API")
InitConfig()
common.SetLogLevel(viper.GetString("log_level"))
err := config.Validate()
if err != nil {
log.WithError(err).Fatalln("Invalid config.")
}
log.Printf("config: %+v", config)
srv := api.New(config)
srv.Start()
ds, err := datastore.New(viper.GetString("db"))
if err != nil {
log.WithError(err).Fatalln("Invalid DB url.")
}
srv := server.New(ds, config)
srv.Run()
}
func InitConfig() {
cwd, _ := os.Getwd()
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.SetDefault("log_level", "info")
viper.SetDefault("db", fmt.Sprintf("bolt://%s/bolt.db?bucket=funcs", cwd))
viper.SetConfigName("config")
viper.AddConfigPath(".")
viper.AutomaticEnv() // picks up env vars automatically
viper.ReadInConfig()
}