forked from panshiqu/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.go
45 lines (35 loc) · 923 Bytes
/
proxy.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
package main
import (
"log"
"os"
"os/signal"
"github.com/panshiqu/framework/define"
"github.com/panshiqu/framework/network"
"github.com/panshiqu/framework/proxy"
"github.com/panshiqu/framework/utils"
)
func handleSignal(server *network.Server, client *network.Client) {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
s := <-c
log.Println("Got signal:", s)
server.Stop()
client.Stop()
}
func main() {
config := &define.ConfigProxy{}
if err := utils.ReadJSON("./config/proxy.json", config); err != nil {
log.Println("ReadJSON ConfigProxy", err)
return
}
server := network.NewServer(config.ListenIP)
client := network.NewClient(config.DialIP)
processor := proxy.NewProcessor(server, client, config)
server.Register(processor)
client.Register(processor)
go handleSignal(server, client)
go client.Start()
if err := server.Start(); err != nil {
log.Println("Start", err)
}
}