...
1 package poll
2
3 import (
4 "net"
5 "os"
6 )
7
8
9 type Check func(t LogT) Result
10
11
12 func FileExists(path string) Check {
13 return func(t LogT) Result {
14 if h, ok := t.(helperT); ok {
15 h.Helper()
16 }
17
18 _, err := os.Stat(path)
19 switch {
20 case os.IsNotExist(err):
21 t.Logf("waiting on file %s to exist", path)
22 return Continue("file %s does not exist", path)
23 case err != nil:
24 return Error(err)
25 default:
26 return Success()
27 }
28 }
29 }
30
31
32
33
34 func Connection(network, address string) Check {
35 return func(t LogT) Result {
36 if h, ok := t.(helperT); ok {
37 h.Helper()
38 }
39
40 _, err := net.Dial(network, address)
41 if err != nil {
42 t.Logf("waiting on socket %s://%s to be available...", network, address)
43 return Continue("socket %s://%s not available", network, address)
44 }
45 return Success()
46 }
47 }
48
View as plain text