-
Notifications
You must be signed in to change notification settings - Fork 22
/
main.go
63 lines (56 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
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"encoding/json"
"flag"
"github.com/JoeCao/cmpp-gateway/gateway"
"io/ioutil"
"log"
"os"
)
func main() {
//
var configPath string
var config = &gateway.Config{}
//
flag.StringVar(&configPath, "c", "", "配置文件路径")
flag.Parse()
if configPath == "" {
configPath = "./config.json"
}
//
err := LoadJsonFile(configPath, config)
if err == nil {
log.Println("加载成功 => ", config)
} else {
log.Fatal("加载失败 ", configPath, " => ", err)
}
go gateway.StartClient(config)
go gateway.StartCmdLine()
go gateway.StartCache(config)
defer gateway.StopCache()
go gateway.Serve(config)
<-gateway.Abort
}
func LoadJsonFile(filePath string, obj interface{}) error {
data, err := ReadBytes(filePath)
if err != nil {
return err
}
err = json.Unmarshal(data, obj)
if err != nil {
return err
}
return nil
}
func ReadBytes(filePath string) ([]byte, error) {
file, err := os.Open(filePath)
if err != nil {
return nil, err
}
defer file.Close()
data, err := ioutil.ReadAll(file)
if err != nil {
return nil, err
}
return data, nil
}