29 lines
517 B
Go
29 lines
517 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
url := "http://127.0.0.1:8080/healthz"
|
|
if len(os.Args) > 1 {
|
|
url = os.Args[1]
|
|
}
|
|
|
|
client := &http.Client{Timeout: 3 * time.Second}
|
|
resp, err := client.Get(url)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "healthcheck error: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
defer func() { _ = resp.Body.Close() }()
|
|
|
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
|
fmt.Fprintf(os.Stderr, "healthcheck failed: status %s\n", resp.Status)
|
|
os.Exit(1)
|
|
}
|
|
}
|