forked from grpc-example/simple
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
42 lines (31 loc) · 687 Bytes
/
client.go
File metadata and controls
42 lines (31 loc) · 687 Bytes
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
package main
import (
"google.golang.org/grpc/credentials/insecure"
"log"
"os"
pb "github.com/grpc-example/simple/pb"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
const (
address = "localhost:50001"
)
func main() {
conn, err := grpc.Dial(address,
grpc.WithTransportCredentials(insecure.NewCredentials()), //禁用https
)
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := pb.NewGreeterClient(conn)
name := "lin"
if len(os.Args) > 1 {
name = os.Args[1]
}
r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: name})
if err != nil {
log.Fatalf("could not greet: %v", err)
}
log.Println(r.Message)
}