MCPcopy
hub / github.com/sourcegraph/checkup / Check

Method Check

check/http/http.go:89–122  ·  view source on GitHub ↗

Check performs checks using c according to its configuration. An error is only returned if there is a configuration error.

()

Source from the content-addressed store, hash-verified

87// Check performs checks using c according to its configuration.
88// An error is only returned if there is a configuration error.
89func (c Checker) Check() (types.Result, error) {
90 if c.Attempts < 1 {
91 c.Attempts = 1
92 }
93 if c.Client == nil {
94 c.Client = DefaultHTTPClient
95 }
96 if c.UpStatus == 0 {
97 c.UpStatus = http.StatusOK
98 }
99
100 result := types.NewResult()
101 result.Title = c.Name
102 result.Endpoint = c.URL
103
104 req, err := http.NewRequest("GET", c.URL, nil)
105 if err != nil {
106 return result, err
107 }
108
109 if c.Headers != nil {
110 for key, header := range c.Headers {
111 req.Header.Add(key, strings.Join(header, ", "))
112 // net/http has special Host field which we'll fill out
113 if strings.ToLower(key) == "host" {
114 req.Host = header[0]
115 }
116 }
117 }
118
119 result.Times = c.doChecks(req)
120
121 return c.conclude(result), nil
122}
123
124// doChecks executes req using c.Client and returns each attempt.
125func (c Checker) doChecks(req *http.Request) types.Attempts {

Callers 1

TestCheckerFunction · 0.95

Implementers 6

fakecheckup_test.go
Checkercheck/http/http.go
Checkercheck/dns/dns.go
Checkercheck/exec/exec.go
Checkercheck/tls/tls.go
Checkercheck/tcp/tcp.go

Calls 3

doChecksMethod · 0.95
concludeMethod · 0.95
NewResultFunction · 0.92

Tested by 1

TestCheckerFunction · 0.76