-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathomlox_test.go
49 lines (38 loc) · 961 Bytes
/
omlox_test.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
// Copyright (c) Omlox Client Go Contributors
// SPDX-License-Identifier: MIT
package omlox_test
import (
"context"
"log"
"github.com/wavecomtech/omlox-client-go"
)
func ExampleNew() {
c, err := omlox.New("localhost:8081/v2")
if err != nil {
log.Fatal(err)
}
trackables, err := c.Trackables.List(context.Background())
if err != nil {
log.Fatal(err)
}
_ = trackables // use trackables
}
func ExampleConnect() {
// Dials a Omlox Hub websocket interface, subscribes to
// the location_updates topic and listens to new
// location messages.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
client, err := omlox.Connect(ctx, "localhost:7081/v2")
if err != nil {
log.Fatal(err)
}
defer client.Close()
sub, err := client.Subscribe(ctx, omlox.TopicLocationUpdates)
if err != nil {
log.Fatal(err)
}
for location := range omlox.ReceiveAs[omlox.Location](sub) {
_ = location // handle location update
}
}