-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (45 loc) · 883 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
51
52
53
54
package main
import (
"os"
"time"
"github.com/BurntSushi/toml"
"github.com/hsyan2008/go-logger/logger"
hfw "github.com/hsyan2008/hfw2"
"github.com/hsyan2008/hfw2/ssh"
)
var config tomlConfig
func init() {
if _, err := toml.DecodeFile("main.toml", &config); err != nil {
logger.Error(err)
os.Exit(1)
}
}
func main() {
var tmpServers = map[string]ssh.SSHConfig{}
for _, v := range config.Server {
tmpServers[v.Group] = v.SSHConfig
}
for _, v := range config.Inner {
l, err := ssh.NewLocalForward(tmpServers[v.Group], v.ForwardIni)
defer l.Close()
if err != nil {
logger.Error(v, err)
return
}
}
_ = hfw.Run()
}
type tomlConfig struct {
Title string
Keep time.Duration
Server []server
Inner []inner
}
type server struct {
Group string `toml:"group"`
ssh.SSHConfig
}
type inner struct {
Group string `toml:"group"`
ssh.ForwardIni
}