-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
58 lines (49 loc) · 1.23 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
//Go-Cortex is a robot that uses the wit.ai api to let you control arduinos, as well as interact with flowdock
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"net/http"
)
var configFile string
var config CortexConfig
func init() {
flag.StringVar(&configFile, "config", "", "path to cortex.config.json file.")
}
func main() {
flag.Parse()
readCortexConfig()
if config.FlowdockAccessToken != "" {
go func() {
listenStream()
}()
}
if config.HttpPort != "" {
http.HandleFunc("/wit", WitHandler)
http.HandleFunc("/sms", NexmoHandler)
http.ListenAndServe(fmt.Sprintf(":%v", config.HttpPort), nil)
}
}
func readCortexConfig() {
configBytes, error := ioutil.ReadFile(configFile)
if error != nil {
log.Fatalf("Could not read config file, error: %+v", error)
}
error = json.Unmarshal(configBytes, &config)
if error != nil {
log.Fatalf("Could not parse json file, got: %+v", error)
}
log.Printf("Using configuration: %+v", config)
}
//CortexConfig hold the configuration for Cortex to work.
type CortexConfig struct {
HttpPort string
CortexEmail string
FlowdockAccessToken string
WitAccessToken string
Flows string
FlowsTicketsUrls []map[string]string
}