From 931d21b0c8fb53515f8dddde16f4390962aa42dd Mon Sep 17 00:00:00 2001 From: robinknaapen Date: Fri, 26 Feb 2021 11:24:46 +0100 Subject: [PATCH] Add executable --- cmd/main.go | 42 ++++++++++++++++++++++++++++++++++++++++++ go.mod | 3 +++ 2 files changed, 45 insertions(+) create mode 100644 cmd/main.go create mode 100644 go.mod diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 0000000..a68d8af --- /dev/null +++ b/cmd/main.go @@ -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) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..9b86dd1 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.fuyu.moe/Fuyu/waitfor + +go 1.15