-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.go
87 lines (72 loc) · 1.83 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
package main
import (
"fmt"
"os"
"sort"
log "github.com/sirupsen/logrus"
"github.com/urfave/cli"
"github.com/cookpad/itacho/server"
)
const progName = "itacho"
// Embed at build time
var version string
func main() {
log.SetLevel(log.DebugLevel)
app := cli.NewApp()
app.Name = progName
app.Usage = "itacho to manange and operate envoy based service mesh"
app.Version = version
app.Commands = []cli.Command{
{
Name: "server",
Aliases: []string{"s"},
Usage: "run xDS POST-GET convert proxy",
Action: serverCmd,
Flags: []cli.Flag{
cli.StringFlag{
Name: "addr, a",
Usage: "[optional] bind address like `[::]` or `0.0.0.0`",
EnvVar: "BIND_ADDR",
},
cli.UintFlag{
Name: "port, p",
Usage: "[optional] bind port like `8080`.",
EnvVar: "BIND_PORT",
},
cli.StringFlag{
Name: "object-storage-endpoint-url, e",
Usage: "an endpoint URL of xDS response storage",
EnvVar: "OBJECT_STORAGE_ENDPOINT_URL",
},
},
},
}
sort.Sort(cli.CommandsByName(app.Commands))
sort.Sort(cli.FlagsByName(app.Flags))
for _, c := range app.Commands {
sort.Sort(cli.FlagsByName(c.Flags))
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func serverCmd(ctx *cli.Context) error {
opts := server.Opts{}
// addr can be empty
opts.BindAddr = ctx.String("addr")
// port can be 0
opts.BindPort = ctx.Uint("port")
endpoint := ctx.String("object-storage-endpoint-url")
if len(endpoint) < 1 {
return buildEmptyFlagError("object-storage-endpoint-url")
}
opts.ObjectStorageEndpoint = endpoint
return server.Start(opts)
}
func buildEmptyFlagError(name string) error {
return fmt.Errorf(`flag "%s" cannot be empty`, name)
}
func buildFlagError(name string, reason string) error {
return fmt.Errorf(`Invalid flag value given for "%s": %s`, name, reason)
}