aboutsummaryrefslogtreecommitdiff
path: root/http.go
blob: 24e0b4d27793aa7af2950481cc65b0af11c14c2a (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, status int) error {
	client := &http.Client{Timeout: 5 * 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
}