feat: stable version
Co-authored-by: Dmitry Fedotov <dmitry@uint32.ru> Co-committed-by: Dmitry Fedotov <dmitry@uint32.ru>
This commit is contained in:
17
checks.go
17
checks.go
@@ -14,12 +14,13 @@ import (
|
||||
const DefaultTimeout = time.Second * 10
|
||||
|
||||
// GetHTTP creates a CheckFunc that operates as follows.
|
||||
// The check calls GET method for provided addr using http.DefaultClient.
|
||||
// The check makes a request with GET method to provided addr using http.DefaultClient.
|
||||
// If request fails within specified timeout the returned status is StatusDown.
|
||||
// The function then tries to read response body. If it fails,
|
||||
// the returned status is StatusDown.
|
||||
// If request secceeds but reponse code is not 200, the returned
|
||||
// status is StatusPartiallyAvailable and response body is contained in the
|
||||
//
|
||||
// If request succeeds but reponse code is not 200, the returned
|
||||
// status is StatusDown and response body is contained in the
|
||||
// returned error.
|
||||
//
|
||||
// GetHTTP return an error if addr can not be parsed with url.Parse.
|
||||
@@ -64,11 +65,11 @@ func GetHTTP(addr string, timeout time.Duration) (CheckFunc, error) {
|
||||
}
|
||||
|
||||
// HeadHTTP creates a CheckFunc that operates as follows.
|
||||
// The check calls GET method for provided addr using http.DefaultClient.
|
||||
// The check make a request with HEAD method to provided addr using http.DefaultClient.
|
||||
// If request fails within specified timeout the returned status is StatusDown.
|
||||
//
|
||||
// If request secceeds but reponse code is not 200, the returned
|
||||
// status is StatusPartiallyAvailable.
|
||||
// If request succeeds but reponse code is not 200, the returned
|
||||
// status is StatusDown.
|
||||
//
|
||||
// HeadHTTP return an error if addr can not be parsed with url.Parse.
|
||||
// If zero timeout is provided then the DefaultTimeout (10 second) is used.
|
||||
@@ -102,16 +103,18 @@ func HeadHTTP(addr string, timeout time.Duration) (CheckFunc, error) {
|
||||
return StatusDown, fmt.Errorf("got HTTP response code %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
return http.StatusOK, nil
|
||||
return StatusOK, nil
|
||||
}, nil
|
||||
}
|
||||
|
||||
// DialTCP creates a CheckFunc that may be used to check tcp connectivity
|
||||
// to a host.
|
||||
//
|
||||
// The check tries to net.DialTimeout to the provided addr. If it fails,
|
||||
// the returned status is StatusDown.
|
||||
//
|
||||
// No validation of addr is made.
|
||||
//
|
||||
// If zero timeout is provided then the DefaultTimeout (10 second) is used.
|
||||
func DialTCP(addr string, timeout time.Duration) (CheckFunc, error) {
|
||||
if timeout == 0 {
|
||||
|
Reference in New Issue
Block a user