@@ 0,0 1,60 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "net/http"
+ "net/url"
+ "os"
+ "time"
+)
+
+var (
+ domainsURL = "http://localhost:8004/_check/domain"
+ timeout = 10
+ debug bool
+)
+
+func main() {
+ domain := os.Getenv("TLSTUNNEL_NAME")
+ if domain == "" {
+ fmt.Fprintf(os.Stderr, "No value set for TLSTUNNEL_NAME\n")
+ os.Exit(1)
+ }
+
+ flag.StringVar(&domainsURL, "url", domainsURL, "url to links-domains service")
+ flag.IntVar(&timeout, "timeout", timeout, "http request timeout value")
+ flag.BoolVar(&debug, "debug", false, "enable debug logging")
+ flag.Parse()
+
+ parts, err := url.Parse(domainsURL)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "Invalid domain URL: %v\n", err)
+ os.Exit(1)
+ }
+ qs := parts.Query()
+ qs.Set("domain", domain)
+ parts.RawQuery = qs.Encode()
+
+ httpClient := &http.Client{
+ Timeout: time.Duration(timeout) * time.Second,
+ }
+ req, err := http.NewRequest("GET", parts.String(), nil)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
+ os.Exit(1)
+ }
+ resp, err := httpClient.Do(req)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "ERROR: %v\n", err)
+ os.Exit(1)
+ }
+ defer resp.Body.Close()
+
+ if resp.StatusCode < 200 || resp.StatusCode > 299 {
+ // Invalid domain
+ os.Exit(1)
+ }
+ // Valid domain, explicit
+ os.Exit(0)
+}