Files
aitrade/cmd/healthcheck/main.go
T
kaedwen ea141eb012
Build and Push Docker Image / build-and-push (push) Failing after 1m41s
initial
2026-07-02 20:09:44 +02:00

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)
}