-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathclient.go
61 lines (49 loc) · 1.54 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package client
import (
"gopkg.in/src-d/proteus.v1/example"
"gopkg.in/src-d/proteus.v1/example/categories"
"golang.org/x/net/context"
"google.golang.org/grpc"
)
type Client struct {
example.ExampleServiceClient
Conn *grpc.ClientConn
}
func (c *Client) Close() {
c.Conn.Close()
}
func (c *Client) RequestRandomNumber(mean, std float64) (float64, error) {
res, err := c.RandomNumber(context.Background(), &example.RandomNumberRequest{
Arg1: mean,
Arg2: std,
})
if err != nil {
return 0, err
}
return res.Result1, nil
}
func (c *Client) RequestAlphaTime() (*example.MyTime, error) {
return c.GetAlphaTime(context.Background(), &example.GetAlphaTimeRequest{})
}
func (c *Client) RequestOmegaTime() (*example.MyTime, error) {
return c.GetOmegaTime(context.Background(), &example.GetOmegaTimeRequest{})
}
func (c *Client) RequestRandomCategory() (*categories.CategoryOptions, error) {
return c.RandomCategory(context.Background(), &example.RandomCategoryRequest{})
}
func (c *Client) RequestPhone() (*example.Product, error) {
return c.GetPhone(context.Background(), &example.GetPhoneRequest{})
}
func (c *Client) RequestDurationForLength(meters int64) (*example.MyDuration, error) {
return c.GetDurationForLength(context.Background(), &example.GetDurationForLengthRequest{meters})
}
func NewClient(addr string) (*Client, error) {
conn, err := grpc.Dial("localhost:8001", grpc.WithInsecure())
if err != nil {
return nil, err
}
return &Client{
ExampleServiceClient: example.NewExampleServiceClient(conn),
Conn: conn,
}, nil
}