2021-04-11 14:08:29 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-06-19 21:54:07 +00:00
|
|
|
"context"
|
2021-04-11 14:08:29 +00:00
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"net/http"
|
2021-06-19 21:54:07 +00:00
|
|
|
"time"
|
2021-04-11 14:08:29 +00:00
|
|
|
)
|
|
|
|
|
2021-06-06 12:39:42 +00:00
|
|
|
func (a *goBlog) healthcheck() bool {
|
2021-06-19 21:54:07 +00:00
|
|
|
timeoutContext, cancelFunc := context.WithTimeout(context.Background(), 10*time.Second)
|
|
|
|
defer cancelFunc()
|
|
|
|
req, err := http.NewRequestWithContext(timeoutContext, http.MethodGet, a.getFullAddress("/ping"), nil)
|
2021-04-11 14:08:29 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
return false
|
|
|
|
}
|
2021-06-19 06:37:16 +00:00
|
|
|
resp, err := a.httpClient.Do(req)
|
2021-04-11 14:08:29 +00:00
|
|
|
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
|
|
|
|
2021-06-06 12:39:42 +00:00
|
|
|
func (a *goBlog) healthcheckExitCode() int {
|
|
|
|
if a.healthcheck() {
|
2021-05-07 14:14:15 +00:00
|
|
|
return 0
|
|
|
|
} else {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
}
|