-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
65 lines (53 loc) · 1.57 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright 2014 Zubair Hamed. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"encoding/json"
"flag"
"github.com/thingfu/hub/api"
"github.com/thingfu/hub/container"
"github.com/thingfu/hub/setup"
"io/ioutil"
"log"
_ "net/http/pprof"
)
func main() {
// Read -home parameter and, if specified, use that as home directory
// for reading thing definitions, rules and config
homeFlag := flag.String("home", "./home", "Home directory of node")
flag.Parse()
home := *homeFlag
log.Println("[INFO] Starting GoHome Node..")
log.Println("[INFO] Home: " + home)
log.Println("[INFO] Learning Kung-Fu..")
// Read config file and parse
content, err := ioutil.ReadFile(string(home + "/" + api.CONFIG_FILE))
if err != nil {
log.Fatal("Error parsing hub config: %v", err)
}
var config api.Configuration
err = json.Unmarshal(content, &config)
if err != nil {
log.Fatalf("StartUp Error - Parsing Hub config: %v", err)
}
// Do any validation on config, set sensible defaults or die if any
// faults or missing config found
validateConfig(&config)
// Initialize IoC container
_, env := container.Initialize(home, config)
// Do setup process
setup.Setup(env)
}
func validateConfig(cfg *api.Configuration) {
if cfg.Db == "" {
log.Fatal("Database Parameter Missing")
}
if cfg.ServerPort == 0 {
log.Println("Server port not defined. Defaulting to 8181")
cfg.ServerPort = 8181
}
if len(cfg.Channels) == 0 {
log.Println("No channels defined. Will only work via HTTP.")
}
}