-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (63 loc) · 1.26 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"context"
"log"
"os"
"github.com/shirou/mqtunnel"
"github.com/urfave/cli/v2"
"go.uber.org/zap"
)
func main() {
app := &cli.App{
Name: "mqtunnel",
Usage: "tunnel via MQTT",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "conf",
Aliases: []string{"c"},
Value: "config.json",
Usage: "config file",
Required: true,
},
&cli.BoolFlag{
Name: "verbose",
Aliases: []string{"v"},
Value: false,
Usage: "verbose",
},
&cli.IntFlag{
Name: "local",
Aliases: []string{"l"},
Value: 0,
Usage: "local port",
},
&cli.IntFlag{
Name: "remote",
Aliases: []string{"r"},
Value: 0,
Usage: "remote port",
},
},
Action: func(cCtx *cli.Context) error {
logger := setupLog(cCtx.Bool("verbose"))
defer logger.Sync()
undo := zap.ReplaceGlobals(logger)
defer undo()
conf, err := mqtunnel.ReadConfig(cCtx.String("conf"))
if err != nil {
return err
}
mqt, err := mqtunnel.NewMQTunnel(conf)
if err != nil {
return err
}
local := cCtx.Int("local")
remote := cCtx.Int("remote")
ctx := context.Background()
return mqt.Start(ctx, local, remote)
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}