Move pinger into healthz
parent
91a3a5474c
commit
1f587b3138
12
healthz.go
12
healthz.go
|
@ -14,3 +14,15 @@ func healthz(w http.ResponseWriter) {
|
|||
fmt.Fprintf(w, "ver: %v\n", version)
|
||||
fmt.Fprintf(w, "go ver: %v\n", runtime.Version())
|
||||
}
|
||||
|
||||
func ping(url string) error {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
return fmt.Errorf("agent returned non-200 status code")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
14
main.go
14
main.go
|
@ -33,7 +33,7 @@ func main() {
|
|||
|
||||
// Perform health check on running instance
|
||||
if healthCheck {
|
||||
err := ping()
|
||||
err := ping(fmt.Sprintf("http://localhost:%d/healthz", port))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -57,15 +57,3 @@ func main() {
|
|||
log.Println("main: Listening on port", port)
|
||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), router))
|
||||
}
|
||||
|
||||
func ping() error {
|
||||
resp, err := http.Get(fmt.Sprintf("http://localhost:%d/healthz", port))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
return fmt.Errorf("agent returned non-200 status code")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue