-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
72 lines (62 loc) · 1.62 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
package main
import (
"context"
"fmt"
"os"
"runtime"
"google.golang.org/grpc"
"github.com/dyweb/go.ice/example/github/pkg/icehubpb"
mygrpc "github.com/dyweb/go.ice/example/github/pkg/transport/grpc"
icli "github.com/dyweb/go.ice/ice/cli"
dlog "github.com/dyweb/gommon/log"
"github.com/spf13/cobra"
)
const (
myname = "icehubctl"
)
var (
version string
commit string
buildTime string
buildUser string
goVersion = runtime.Version()
)
var buildInfo = icli.BuildInfo{Version: version, Commit: commit, BuildTime: buildTime, BuildUser: buildUser, GoVersion: goVersion}
var log, logReg = dlog.NewApplicationLoggerAndRegistry("icehubctl")
var addr = "localhost:7081"
var conn *grpc.ClientConn
var client mygrpc.IceHubClient
var pingCmd = &cobra.Command{
Use: "ping",
Short: "ping server",
Long: "Ping server using gRPC",
Run: func(cmd *cobra.Command, args []string) {
mustCreateClient()
if res, err := client.Ping(context.Background(), &icehubpb.Ping{Name: myname}); err != nil {
log.Fatalf("failed to ping %v", err)
} else {
log.Infof("ping finished name is %s", res.Name)
}
},
}
func main() {
cli := icli.New(
icli.Name(myname),
icli.Description("Client of IceHub, which is an example GitHub integration service using go.ice"),
icli.Version(buildInfo),
icli.LogRegistry(logReg))
root := cli.Command()
root.AddCommand(pingCmd)
if err := root.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func mustCreateClient() {
var err error
conn, err = grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
log.Fatalf("can't dial %v", err)
}
client = mygrpc.NewClient(conn)
}