/
check.go
47 lines (41 loc) · 1.05 KB
/
check.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
package poll
import (
"net"
"os"
)
// Check is a function which will be used as check for the WaitOn method.
type Check func(t LogT) Result
// FileExists looks on filesystem and check that path exists.
func FileExists(path string) Check {
return func(t LogT) Result {
if h, ok := t.(helperT); ok {
h.Helper()
}
_, err := os.Stat(path)
switch {
case os.IsNotExist(err):
t.Logf("waiting on file %s to exist", path)
return Continue("file %s does not exist", path)
case err != nil:
return Error(err)
default:
return Success()
}
}
}
// Connection try to open a connection to the address on the
// named network. See net.Dial for a description of the network and
// address parameters.
func Connection(network, address string) Check {
return func(t LogT) Result {
if h, ok := t.(helperT); ok {
h.Helper()
}
_, err := net.Dial(network, address)
if err != nil {
t.Logf("waiting on socket %s://%s to be available...", network, address)
return Continue("socket %s://%s not available", network, address)
}
return Success()
}
}