-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_service_managed_minimal_test.go
56 lines (49 loc) · 1.41 KB
/
example_service_managed_minimal_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
50
51
52
53
54
55
56
package framework_test
import (
"log"
"github.com/openchirp/framework"
)
type Device struct {
}
func NewDevice() framework.Device {
d := new(Device)
return framework.Device(d)
}
func (d *Device) ProcessLink(ctrl *framework.DeviceControl) string {
return "Success"
}
func (d *Device) ProcessUnlink(ctrl *framework.DeviceControl) {
}
func (d *Device) ProcessConfigChange(ctrl *framework.DeviceControl, cchanges, coriginal map[string]string) (string, bool) {
return "", false
}
func (d *Device) ProcessMessage(ctrl *framework.DeviceControl, msg framework.Message) {
}
// ExampleStartServiceClientManaged_minimal demonstates the minimal configuration
// to use StartServiceClientManaged
func ExampleStartServiceClientManaged_minimal() {
// Parse parameters from command line or environment variables
frameworkServer := "http://localhost:7000"
mqttServer := "localhost:1883"
serviceId := "5a1ea73df76abe01c57abfb8"
serviceToken := "DJpHxwmExGbcYwsEHgQezDVeKS4N"
c, err := framework.StartServiceClientManaged(
frameworkServer,
mqttServer,
serviceId,
serviceToken,
"Unexpected disconnect!",
NewDevice)
if err != nil {
log.Fatalln("Failed to StartServiceClient: ", err)
}
defer c.StopClient()
log.Println("Started service")
/* Post service's global status */
err = c.SetStatus("Started")
if err != nil {
log.Fatalln("Failed to publish service status: ", err)
return
}
log.Println("Published Service Status")
}