-
Notifications
You must be signed in to change notification settings - Fork 61
/
grpc_client.go
55 lines (45 loc) · 1.07 KB
/
grpc_client.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
package main
import (
"context"
"flag"
"time"
grpcClient "github.com/hb-go/micro-plugins/client/istio_grpc"
"github.com/micro/go-micro/api/proto"
"github.com/micro/go-micro/client"
"github.com/micro/go-micro/util/log"
example "github.com/hb-go/micro/istio/grpc/api/proto/example"
)
var (
address string
)
func init() {
// local:localhost:8082
// k8s:"192.168.99.100:31380"
flag.StringVar(&address, "address", "localhost:8082", "server address.")
flag.Parse()
}
func main() {
c := grpcClient.NewClient(
client.ContentType("application/json"),
func(o *client.Options) {
o.CallOptions.Address = address
},
)
client := example.NewExampleService("go.micro.api.sample", c)
post := make(map[string]*go_api.Pair)
post["name"] = &go_api.Pair{
Key: "name",
Values: []string{"Hobo"},
}
req := &go_api.Request{
Method: "POST",
Post: post,
}
now := time.Now()
resp, err := client.Call(context.Background(), req)
if err != nil {
log.Logf("did not connect: %v", err)
}
log.Logf("resp: %v", resp)
log.Logf("duration: %s", time.Since(now).String())
}