-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (41 loc) · 905 Bytes
/
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
package main
import (
"fmt"
"os"
"encoding/json"
"taxistream/base"
"taxistream/taxisim"
"taxistream/taxisite"
_ "github.com/lib/pq"
"runtime"
)
// Reads a configuration file.
// The file needs to adhere to the Configuration struct.
func readConfig(configFile string) base.Configuration {
file, err1 := os.Open(configFile)
if err1 != nil {
panic(err1)
}
defer file.Close()
decoder := json.NewDecoder(file)
configuration := base.Configuration{}
err2 := decoder.Decode(&configuration)
if err2 != nil {
panic(err2)
}
return configuration
}
// Main function of the processing program.
func main() {
conf := readConfig("config.json")
fmt.Println(conf)
switch conf.Mode {
case "process":
taxisim.RunSim(conf)
case "stream":
runtime.GOMAXPROCS(4)
taxisite.ExposeEndpoints(conf)
default:
fmt.Println("Please specify run 'mode' in config file: {'process', 'stream'}.")
}
}