GoBlog/healthcheck.go

32 lines
528 B
Go
Raw Normal View History

2021-04-11 14:08:29 +00:00
package main
import (
"fmt"
"io"
"net/http"
)
func (a *goBlog) healthcheck() bool {
req, err := http.NewRequest(http.MethodGet, a.getFullAddress("/ping"), nil)
2021-04-11 14:08:29 +00:00
if err != nil {
fmt.Println(err.Error())
return false
}
resp, err := appHttpClient.Do(req)
if err != nil {
fmt.Println(err.Error())
return false
}
defer resp.Body.Close()
_, _ = io.Copy(io.Discard, resp.Body)
return resp.StatusCode == 200
}
2021-05-07 14:14:15 +00:00
func (a *goBlog) healthcheckExitCode() int {
if a.healthcheck() {
2021-05-07 14:14:15 +00:00
return 0
} else {
return 1
}
}