-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (31 loc) · 799 Bytes
/
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
package main
import (
"encoding/json"
"log"
"net"
"os"
)
func main() {
if _, err := os.Stat("config.json"); err != nil {
handleErrors("Unable to find config file", err)
}
configFile, err := os.Open("config.json")
handleErrors("Unable to open config file", err)
defer configFile.Close()
var apps Config
decoder := json.NewDecoder(configFile)
if err := decoder.Decode(&apps); err != nil {
handleErrors("Unable to decode JSON", err)
}
for _, app := range apps.Apps {
connChannel := make(chan net.Conn)
log.Println("Starting listeners for", app.Name)
for _, port := range app.Ports {
server := Server{Port: port, Targets: app.Targets}
log.Println("Listening on port", port)
go server.Listen(connChannel)
}
go proxy(connChannel, app.Targets)
}
select {}
}