-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmain.go
64 lines (51 loc) · 1.16 KB
/
main.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 (
"errors"
"github.com/sohamkamani/detective"
"net/http"
"time"
)
type cache struct {
}
func (c cache) ping() error {
return nil
}
type db struct {
}
func (d db) ping() error {
return nil
}
func main() {
// First detective instance instance
d := detective.New("your application")
dep1 := d.Dependency("cache")
dep1.Detect(func() error {
time.Sleep(250 * time.Millisecond)
return nil
})
d.Dependency("db").Detect(func() error {
time.Sleep(250 * time.Millisecond)
return nil //errors.New("failed")
})
// Register another detective instance running at localhost:8080
d.Endpoint("http://localhost:8080")
go func() {
if err := http.ListenAndServe(":8081", d); err != nil {
panic(err)
}
}()
// Initialize a second detective instance
d2 := detective.New("Another application")
// Create a dependency, and register its detector function
d2.Dependency("cache").Detect(func() error {
time.Sleep(50 * time.Millisecond)
return nil
})
d2.Dependency("db").Detect(func() error {
time.Sleep(50 * time.Millisecond)
return errors.New("fail")
})
if err := http.ListenAndServe(":8080", d2); err != nil {
panic(err)
}
}