-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
89 lines (79 loc) · 1.61 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"context"
"os"
"os/signal"
"sync"
"syscall"
"github.com/gookit/color"
"github.com/urfave/cli/v2"
)
type lockOut struct {
lk sync.Mutex
}
func (w *lockOut) Write(p []byte) (n int, err error) {
w.lk.Lock()
defer w.lk.Unlock()
return os.Stdout.Write(p)
}
var lkout = &lockOut{}
func main() {
app := cli.NewApp()
app.Usage = "grpc protocol capture & decode"
app.Version = "v1.0.0"
app.Authors = []*cli.Author{{
Name: "kkhaike",
Email: "[email protected]",
}}
app.Flags = []cli.Flag{
&cli.IntFlag{
Name: "snapshot-length",
Aliases: []string{"s"},
Value: 262144,
},
&cli.StringFlag{
Name: "interface",
Aliases: []string{"i"},
Required: true,
},
&cli.StringFlag{
Name: "path-regex",
Aliases: []string{"P"},
Usage: "focus to show",
},
&cli.BoolFlag{
Name: "force",
Usage: "enable on-the-fly decode(use with pcap-filter)",
},
&cli.BoolFlag{
Name: "hide-no-path",
Usage: "non-path packet can't decode",
},
&cli.StringSliceFlag{
Name: "proto-include",
Aliases: []string{"I"},
Usage: "use like protoc -I",
},
&cli.StringSliceFlag{
Name: "proto-file",
Aliases: []string{"f"},
Usage: "proto relative path about proto-include",
},
&cli.BoolFlag{
Name: "verbose",
},
}
app.ArgsUsage = "pcap-filter"
app.Action = capAction
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGTERM, syscall.SIGINT)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
<-c
cancel()
}()
if err := app.RunContext(ctx, os.Args); err != nil {
color.Errorln(err)
}
}