-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
probe.go
42 lines (34 loc) · 891 Bytes
/
probe.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package probe
import (
"fmt"
"net/http"
"net/url"
"time"
)
// http Client for probing
// Use our custom client since DefaultClient specifies timeout of 0 (no timeout).
// See https://medium.com/@nate510/don-t-use-go-s-default-http-client-4804cb19f779.
// Use a timeout of 30s.
var client = &http.Client{Timeout: 30 * time.Second}
// GetHello performs a GET request on the /hello endpoint
func GetHello(host string) error {
hostURL, err := url.Parse(host)
if err != nil {
return err
}
requestURL, err := hostURL.Parse("/hello")
if err != nil {
return err
}
resp, err := client.Get(requestURL.String())
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("unexpected status code: %d %s", resp.StatusCode, resp.Status)
}
return nil
}