-
Notifications
You must be signed in to change notification settings - Fork 109
/
client.go
66 lines (56 loc) · 1.39 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
62
63
64
65
66
// Package main tests out a Gizmo client.
package main
import (
"context"
"github.com/edaniels/golog"
"go.viam.com/rdk/examples/customresources/apis/gizmoapi"
"go.viam.com/rdk/robot/client"
)
func main() {
logger := golog.NewDebugLogger("client")
robot, err := client.New(
context.Background(),
"localhost:8080",
logger,
)
if err != nil {
logger.Fatal(err)
}
//nolint:errcheck
defer robot.Close(context.Background())
res, err := robot.ResourceByName(gizmoapi.Named("gizmo1"))
if err != nil {
logger.Fatal(err)
}
comp1 := res.(gizmoapi.Gizmo)
ret1, err := comp1.DoOne(context.Background(), "hello")
if err != nil {
logger.Fatal(err)
}
logger.Info(ret1)
ret2, err := comp1.DoOneClientStream(context.Background(), []string{"hello", "arg1", "foo"})
if err != nil {
logger.Fatal(err)
}
logger.Info(ret2)
ret2, err = comp1.DoOneClientStream(context.Background(), []string{"arg1", "arg1", "arg1"})
if err != nil {
logger.Fatal(err)
}
logger.Info(ret2)
ret3, err := comp1.DoOneServerStream(context.Background(), "hello")
if err != nil {
logger.Fatal(err)
}
logger.Info(ret3)
ret3, err = comp1.DoOneBiDiStream(context.Background(), []string{"hello", "arg1", "foo"})
if err != nil {
logger.Fatal(err)
}
logger.Info(ret3)
ret3, err = comp1.DoOneBiDiStream(context.Background(), []string{"arg1", "arg1", "arg1"})
if err != nil {
logger.Fatal(err)
}
logger.Info(ret3)
}