-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.go
65 lines (56 loc) · 1.39 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
package main
import (
"context"
"fmt"
"time"
"github.com/bketelsen/microclass/module4/userservice/proto/account"
"github.com/micro/go-micro/client"
"github.com/micro/profile-srv/proto/record"
)
func main() {
cl := account.NewAccountClient("go.micro.srv.user", client.DefaultClient)
req := &account.LoginRequest{
Username: "gopher",
Password: "password1",
}
var rsp *account.LoginResponse
var err error
ctx, cxl := context.WithTimeout(context.Background(), 1*time.Second)
defer cxl()
// Call service
if rsp, err = cl.Login(ctx, req); err != nil {
fmt.Println("call err: ", err, rsp)
return
}
fmt.Println("Found account:", rsp.Session.GetUsername())
sreq := &account.SearchRequest{
Username: "gopher",
Limit: 10,
}
var srsp *account.SearchResponse
if srsp, err = cl.Search(ctx, sreq); err != nil {
fmt.Println("call err:", err, srsp)
}
var foundUser *account.User
if srsp.Users != nil {
if len(srsp.Users) > 0 {
foundUser = srsp.Users[0]
} else {
fmt.Println("no user found")
return
}
} else {
fmt.Println("Got no users")
return
}
profcl := record.NewRecordClient("go.micro.srv.profile", client.DefaultClient)
profreq := &record.ReadRequest{
Id: foundUser.GetId(),
}
var profrsp *record.ReadResponse
if profrsp, err = profcl.Read(ctx, profreq); err != nil {
fmt.Println("call err:", err, profrsp)
return
}
fmt.Println(profrsp.Profile)
}