-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmain.go
72 lines (56 loc) · 1.41 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
64
65
66
67
68
69
70
71
72
package main
import (
"flag"
"os"
"os/signal"
"syscall"
"github.com/polevpn/anyvalue"
"github.com/polevpn/elog"
"github.com/polevpn/polevpn_gateway/core"
)
var Config *anyvalue.AnyValue
var configPath string
var pc *core.PoleVpnGateway
func init() {
flag.StringVar(&configPath, "config", "./config.json", "config file path")
}
func signalHandler() {
c := make(chan os.Signal)
signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
go func() {
for s := range c {
switch s {
case syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT:
elog.Info("receive exit signal,exit")
if pc != nil {
pc.Stop()
}
elog.Flush()
os.Exit(0)
default:
}
}
}()
}
func main() {
flag.Parse()
defer elog.Flush()
signalHandler()
var err error
Config, err = core.GetConfig(configPath)
if err != nil {
elog.Fatal("load config fail", err)
}
client := core.NewPoleVpnGateway()
routeServer := Config.Get("route_server").AsStr("127.0.0.1:443")
sharedKey := Config.Get("key").AsStr()
gatewayIp := Config.Get("gateway").AsStr()
localNetWork := Config.Get("local_networks").AsArray()
routeNetWorks := Config.Get("route_networks").AsArray()
acls := Config.Get("acls").AsArray()
err = client.Start(routeServer, sharedKey, gatewayIp, localNetWork, routeNetWorks, acls)
if err != nil {
elog.Fatal("start polevpn client fail,", err)
}
client.WaitStop()
}