-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
50 lines (41 loc) · 997 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
41
42
43
44
45
46
47
48
49
50
package main
import (
"flag"
"github.com/zwily/turbotunnel/server"
"io/ioutil"
"launchpad.net/goyaml"
"log"
"os"
"os/signal"
"syscall"
)
type TunnelDef struct {
Name string
LocalPort int `yaml:"localPort"`
JumpHost string `yaml:"jumpHost"`
RemoteHost string `yaml:"remoteHost"`
RemotePort int `yaml:"remotePort"`
EnvCommand string `yaml:"envCommand"`
}
type Config struct {
Tunnels []TunnelDef
}
func main() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
var configPath = flag.String("config", "", "Path to config file")
flag.Parse()
configYaml, err := ioutil.ReadFile(*configPath)
if err != nil {
log.Fatal(err)
}
var config Config
goyaml.Unmarshal(configYaml, &config)
for _, t := range config.Tunnels {
s := server.New(t.Name, t.LocalPort, t.JumpHost, t.RemoteHost, t.RemotePort, t.EnvCommand)
go s.Listen()
defer s.Close()
}
sigchan := make(chan os.Signal)
signal.Notify(sigchan, syscall.SIGINT, syscall.SIGTERM)
<-sigchan
}