Simple blogging system written in Go https://goblog.app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

38 lines
751 B

package main
import (
"context"
"fmt"
"log"
"net/http"
"time"
)
func (a *goBlog) healthcheck() bool {
if a.tailscaleEnabled() {
log.Println("Skip healthcheck because Tailscale is enabled")
return true
}
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(err.Error())
return false
}
resp, err := a.httpClient.Do(req)
if err != nil {
fmt.Println(err.Error())
return false
}
defer resp.Body.Close()
return resp.StatusCode == 200
}
func (a *goBlog) healthcheckExitCode() int {
if a.healthcheck() {
return 0
} else {
return 1
}
}