/api/v1/streaming/health

master
Charles Iliya Krempeaux 2024-08-01 18:27:14 -07:00
parent b071e5376c
commit eca6289ce5
3 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,9 @@
package health
import (
"github.com/reiver/go-erorr"
)
const (
errNilHTTPResponse = erorr.Error("mstdn: nil http-response")
)

View File

@ -0,0 +1,36 @@
package health
import (
"net/http"
"net/url"
)
// IsOK return true if the host is "alive".
//
// The way to checks if the host is "alive" is by making
// an HTTP request to "/api/v1/streaming/health".
// If the HTTP-status-code of the HTTP-response is "200",
// it returns true.
//
// This is part of the Mastodon client-server API.
//
// See:
// https://docs.joinmastodon.org/methods/streaming/#health
func IsOK(host string) (bool, error) {
var urloc = url.URL{
Scheme:"https",
Host:host,
Path:Path,
}
resp, err := http.Get(urloc.String())
if nil != err {
return false, err
}
if nil == resp {
return false, errNilHTTPResponse
}
return http.StatusOK == resp.StatusCode, nil
}

View File

@ -0,0 +1,5 @@
package health
const Path string = "/api/v1/streaming/health"