-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
56 lines (46 loc) · 816 Bytes
/
server.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
package main
import (
"encoding/json"
"flag"
"io/ioutil"
"log"
"math/rand"
"os"
"time"
"./server"
)
var config server.Config
func readConfigOrDie(path string) error {
file, err := os.Open(path)
if err != nil {
return err
}
buffer, err := ioutil.ReadAll(file)
if err != nil {
return err
}
if err := json.Unmarshal(buffer, &config); err != nil {
return err
}
return err
}
func main() {
path := flag.String("c", "", "Path to the JSON config")
log.SetFlags(log.Flags() | log.Lshortfile)
flag.Parse()
if *path == "" {
flag.PrintDefaults()
os.Exit(1)
}
if err := readConfigOrDie(*path); err != nil {
log.Fatal(err)
}
rand.Seed(time.Now().UnixNano())
s, err := server.New(config)
if err != nil {
log.Fatal(err)
}
if err := s.Listen(); err != nil {
log.Fatal(err)
}
}