package platform import ( "context" "fmt" "net" "net/http" "time" ) // ProbeLocal asks the local health endpoint on listen (e.g. ":8081") whether // the process is alive. Images without a shell run it as their HEALTHCHECK. func ProbeLocal(ctx context.Context, listen 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)+"/healthz", 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 }