-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
41 lines (34 loc) · 1.09 KB
/
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
package main
import (
"context"
"log"
"google.golang.org/grpc"
pb "ummsgo/pb"
)
func registerUser(client pb.UserServiceClient, username, email string) {
resp, err := client.RegisterUser(context.Background(),
&pb.RegisterUserRequest{Username: username, Email: email})
if err != nil {
log.Fatalf("error: could not register user: %v", err)
}
log.Printf("info: register response: %s", resp.ResponseMessage)
}
func getUser(client pb.UserServiceClient, username string) {
resp, err := client.GetUser(context.Background(),
&pb.GetUserRequest{Username: username})
if err != nil {
log.Fatalf("error: could not get user: %v", err)
}
log.Printf("info: user: %s, email: %s", resp.Username, resp.Email)
}
func main() {
conn, err := grpc.Dial("localhost:6666",
grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
log.Fatalf("error: could not connect: %v", err)
}
defer conn.Close()
client := pb.NewUserServiceClient(conn)
registerUser(client, "nosferatu", "nosferatu@orava.castle")
getUser(client, "nosferatu")
}