aboutsummaryrefslogtreecommitdiff
path: root/http.go
blob: daf8945451b2bfadf4f7175e6f3a60b0b28abbba (plain) (blame)
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
package checkup

import (
	"fmt"
	"net/http"
	"time"
)

func HttpStatusOK(url string, timeout, status int) error {
	client := &http.Client{Timeout: time.Duration(timeout) * time.Second}

	resp, err := client.Get(url)

	if err != nil {
		return err
	}

	defer resp.Body.Close()

	if resp.StatusCode != status {
		return fmt.Errorf("Bad status code, expected %d got: %d",
			status, resp.StatusCode)
	}

	return nil
}