Internal refactoring. Removing the global config.

This commit is contained in:
claudemiro
2016-03-06 15:34:12 -03:00
parent f07549fb6a
commit 1bae7f13ad
13 changed files with 347 additions and 254 deletions
+28 -7
View File
@@ -14,25 +14,46 @@ import (
log "github.com/golang/glog"
)
// Conf holds the global configuration state
var conf configFile
// Start Parse the configuration file and starts the ipe server
// It Panic if could not start the HTTP or HTTPS server
func Start(configfile string) {
func Start(filename string) {
var conf configFile
rand.Seed(time.Now().Unix())
file, err := os.Open(configfile)
file, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
// Reading config
if err := json.NewDecoder(file).Decode(&conf); err != nil {
log.Fatal(err)
}
conf.Init()
router := newRouter()
// Using a in memory database
db := newMemdb()
// Adding applications
for _, a := range conf.Apps {
db.AddApp(newAppFromConfig(a))
}
// Creating the global application context
ctx := &applicationContext{DB: db}
// The router
router := newRouter(ctx)
router.POST("/apps/{app_id}/events", commonHandlers(ctx, postEvents))
router.GET("/apps/{app_id}/channels", commonHandlers(ctx, getChannels))
router.GET("/apps/{app_id}/channels/{channel_name}", commonHandlers(ctx, getChannel))
router.GET("/apps/{app_id}/channels/{channel_name}/users", commonHandlers(ctx, getChannelUsers))
router.GET("/app/{key}", handlerHTTPCFunc(wsHandler))
if conf.SSL {
go func() {