package platform import ( "context" "fmt" "net" "net/http" "time" ) // ProbeLocal asks a local health endpoint (path /healthz or /readyz) on // listen, e.g. ":8081". Images without a shell run it as their HEALTHCHECK. func ProbeLocal(ctx context.Context, listen, path string) error { host, port, err := net.SplitHostPort(listen) if err != nil { return err } if host == "" || host == "0.0.0.0" || host == "::" { host = "127.0.0.1" } ctx, cancel := context.WithTimeout(ctx, 3*time.Second) defer cancel() req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://"+net.JoinHostPort(host, port)+path, nil) if err != nil { return err } resp, err := http.DefaultClient.Do(req) if err != nil { return err } _ = resp.Body.Close() if resp.StatusCode >= 300 { return fmt.Errorf("platform: health endpoint answered %s", resp.Status) } return nil }