-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (46 loc) · 1.08 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
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"os"
"runtime"
)
var (
Version, Build string
conf *Config
)
type Config struct {
Host string `json:"host"`
AesKey string `json:"aeskey"`
Token string `json:"token"`
}
func loadConfig(fname string) {
c := &Config{}
f, err := os.Open(fname)
if err != nil {
log.Fatalf("open config file fail %s", err.Error())
}
if err = json.NewDecoder(f).Decode(c); err != nil {
log.Fatalf("parse config file fail %s", err.Error())
}
conf = c
}
func main() {
version := flag.Bool("version", false, "build version")
confile := flag.String("config", "config.json", "config file")
flag.Parse()
if *version {
fmt.Printf("Version: %s Build: %s\nGo Version: %s\nGo OS/ARCH: %s %s\n", Version, Build, runtime.Version(), runtime.GOOS, runtime.GOARCH)
return
}
loadConfig(*confile)
s, err := NewBotServer()
if err != nil {
log.Fatalf("Error creating server: %v", err)
}
log.Printf("Listening on :%v ...", conf.Host)
log.Fatalf("Error listening on %v: %v", conf.Host, http.ListenAndServe(conf.Host, s))
}