Add executable #1
42
cmd/main.go
Normal file
42
cmd/main.go
Normal file
@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.fuyu.moe/Fuyu/waitfor"
|
||||
)
|
||||
|
||||
var settings = struct {
|
||||
Endpoints []string
|
||||
Timeout time.Duration
|
||||
}{
|
||||
Endpoints: strings.Split(os.Getenv("WAITFOR"), `,`),
|
||||
Timeout: time.Second * 10,
|
||||
}
|
||||
|
||||
func init() {
|
||||
d, err := time.ParseDuration(os.Getenv("WAITFOR_TIMEOUT"))
|
||||
if err == nil {
|
||||
settings.Timeout = d
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
for _, endpoint := range settings.Endpoints {
|
||||
endpoint = strings.TrimSpace(endpoint)
|
||||
if endpoint == `` {
|
||||
continue
|
||||
}
|
||||
|
||||
// Validate endpoint
|
||||
_, _, err := net.SplitHostPort(endpoint)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
waitfor.Try(`tcp`, endpoint, time.Second, settings.Timeout)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user