-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
executable file
·50 lines (39 loc) · 1.24 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
package main
import (
"flag"
debughandler "github.com/real420og/dbgp-proxy/handler/debug"
idehandler "github.com/real420og/dbgp-proxy/handler/ide"
"github.com/real420og/dbgp-proxy/server"
"github.com/real420og/dbgp-proxy/storage"
"log"
"net"
"os"
"os/signal"
"sync"
)
func main() {
ideHostnamePort := flag.String("ide", "0.0.0.0:9002", "ip:port for ide connections")
debugHostnamePort := flag.String("xdebug", "0.0.0.0:9001", "ip:port for xdebug connections")
flag.Parse()
ideConnectionList := storage.NewListIdeConnection()
syncGroup := &sync.WaitGroup{}
ideServer := server.NewServer("ide", resolveTCP(*ideHostnamePort), syncGroup)
debugServer := server.NewServer("debug", resolveTCP(*debugHostnamePort), syncGroup)
go ideServer.Listen(idehandler.NewIdeHandler(ideConnectionList))
go debugServer.Listen(debughandler.NewDebugHandler(ideConnectionList))
log.Println("dbgp proxy started")
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt)
log.Printf("signal: %s", <-signals)
ideServer.Stop()
debugServer.Stop()
syncGroup.Wait()
log.Println("dbgp proxy stopped")
}
func resolveTCP(host string) *net.TCPAddr {
address, err := net.ResolveTCPAddr("tcp", host)
if err != nil {
log.Fatal(err)
}
return address
}