Add executable

This commit is contained in:
Crow Crowcrow 2021-02-26 11:24:46 +01:00
parent d28e60d19f
commit 931d21b0c8
Signed by untrusted user: Crow
GPG Key ID: 45A8E203AF859FD8
2 changed files with 45 additions and 0 deletions

42
cmd/main.go Normal file
View 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)
}
}

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module git.fuyu.moe/Fuyu/waitfor
go 1.15