Add executable #1

Closed
Crow wants to merge 1 commits from Crow/waitfor:executable into master
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