1
0
Fork 0

Move pinger into healthz

master
Ambrose Chua 2018-02-26 23:19:12 +08:00
parent 91a3a5474c
commit 1f587b3138
2 changed files with 13 additions and 13 deletions

View File

@ -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
View File

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