mirror of https://github.com/jlelse/GoBlog
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
667 B
Go
34 lines
667 B
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
func (a *goBlog) healthcheck() bool {
|
|
timeoutContext, cancelFunc := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancelFunc()
|
|
req, err := http.NewRequestWithContext(timeoutContext, http.MethodGet, a.getFullAddress("/ping"), nil)
|
|
if err != nil {
|
|
fmt.Println("healthcheck:", err.Error())
|
|
return false
|
|
}
|
|
resp, err := a.httpClient.Do(req)
|
|
if err != nil {
|
|
fmt.Println("healthcheck:", err.Error())
|
|
return false
|
|
}
|
|
_ = resp.Body.Close()
|
|
return resp.StatusCode == 200
|
|
}
|
|
|
|
func (a *goBlog) healthcheckExitCode() int {
|
|
if a.healthcheck() {
|
|
return 0
|
|
} else {
|
|
return 1
|
|
}
|
|
}
|