-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (43 loc) · 849 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
package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/alecthomas/kong"
"google.golang.org/grpc"
"google.golang.org/grpc/binarylog"
)
type Context struct {
*CLI
}
type CLI struct {
Get GetCmd `cmd:"" help:"Get"`
Put PutCmd `cmd:"" help:"Put"`
Serve ServeCmd `cmd:"" help:"Serve"`
}
func setupBinaryLogging() {
if _, found := os.LookupEnv("GRPC_BINARY_LOG_FILTER"); !found {
return
}
grpc.EnableTracing = true
sink, err := binarylog.NewTempFileSink()
if err != nil {
log.Fatal(err)
}
binarylog.SetSink(sink)
}
func main() {
setupBinaryLogging()
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigs
binarylog.SetSink(nil)
os.Exit(0)
}()
var cli CLI
ctx := kong.Parse(&cli)
err := ctx.Run(&Context{CLI: &cli})
ctx.FatalIfErrorf(err)
}