43 lines
678 B
Go
43 lines
678 B
Go
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)
|
|
}
|
|
}
|