46 lines
746 B
Go
46 lines
746 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
// Get host and port from args or use defaults
|
|
host := "localhost"
|
|
port := "8080"
|
|
|
|
if len(os.Args) > 1 {
|
|
host = os.Args[1]
|
|
}
|
|
if len(os.Args) > 2 {
|
|
port = os.Args[2]
|
|
}
|
|
|
|
url := fmt.Sprintf("http://%s:%s/health", host, port)
|
|
|
|
// Create HTTP client with timeout
|
|
client := &http.Client{
|
|
Timeout: 3 * time.Second,
|
|
}
|
|
|
|
// Make request
|
|
resp, err := client.Get(url)
|
|
if err != nil {
|
|
fmt.Fprintf(os.Stderr, "Health check failed: %v\n", err)
|
|
os.Exit(1)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
// Check status code
|
|
if resp.StatusCode != http.StatusOK {
|
|
fmt.Fprintf(os.Stderr, "Health check failed: HTTP %d\n", resp.StatusCode)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Success
|
|
os.Exit(0)
|
|
}
|