-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (45 loc) · 962 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
47
48
49
50
51
52
package main
import (
"io/ioutil"
"net/http"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "Gothmog"
app.Action = Main
app.Flags = []cli.Flag{
&cli.StringFlag{
Name: "rules",
Usage: "Path to a JSON file containing exported Balrog Rules",
Required: true,
},
}
app.RunAndExitOnError()
}
func Main(c *cli.Context) error {
rawRules, err := ioutil.ReadFile(c.String("rules"))
if err != nil {
return err
}
loadedRules, err := parseRules(rawRules)
if err != nil {
return err
}
gothmogHandler := &GothmogHandler{
rules: &loadedRules,
}
mux := http.NewServeMux()
// We don't have any fixed endpoints; each update request will send data in a specific format
// that gothmogHandler will parse into usable data.
mux.Handle("/", gothmogHandler)
server := &http.Server{
Addr: "127.0.0.1:8888",
Handler: mux,
}
err = server.ListenAndServe()
if err != nil {
return err
}
return nil
}