-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.go
64 lines (50 loc) · 1.16 KB
/
example.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
package main
import (
"encoding/json"
"errors"
"github.com/team142/lux-lucet/lulu"
"log"
)
func main() {
//Start a Health Server
healthServer := lulu.StartHealthServer()
//Set initial state for each subsystem
healthServer.UpdateOk("net/io")
healthServer.UpdateOk("disk/io")
healthServer.UpdateOk("queue-handler")
//Query state
state := healthServer.Query()
//Marshal to json and log json string
b, err := json.Marshal(state)
if err != nil {
log.Fatalln(err)
}
log.Println(string(b))
//Pretend to run some subsystem
runQueueHandler(healthServer)
//Get the state and log the json string
state = healthServer.Query()
b, err = json.Marshal(state)
if err != nil {
log.Fatalln(err)
}
log.Println(string(b))
//Blocking call - do last or `go lulu.StartRestServer...`
lulu.StartRestServer(":9001", healthServer)
}
//Imaginary subsystem
func runQueueHandler(healthServer *lulu.HealthServer) {
// ...
// ...
// ...
//Some work goes wrong here
err := someWork()
if err != nil {
//Example of an update to the system
healthServer.Update("queue-handler", false, err.Error())
return
}
}
func someWork() error {
return errors.New("some error")
}