func WaitFor200()

in projects/aws/bottlerocket-bootstrap/pkg/utils/waiters.go [86:125]


func WaitFor200(url string, timeout time.Duration) error {
	fmt.Printf("Waiting for 200: OK on url %s\n", url)
	counter := 0

	timeoutSignal := time.After(timeout)

	for {
		counter++
		select {
		case <-timeoutSignal:
			return errors.New("Timeout occurred while waiting for 200 OK")
		default:
			fmt.Printf("******  Try %d, hitting url %s ****** \n", counter, url)
			tr := &http.Transport{
				TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
			}
			client := &http.Client{
				Transport: tr,
				// Each call attempt will have a timeout of 1 minute
				Timeout: 1 * time.Minute,
			}
			resp, err := client.Get(url)
			if err != nil {
				fmt.Printf("Error occured while hitting url: %v\n", err)
				time.Sleep(time.Second * 10)
				continue
			}
			body, err := ioutil.ReadAll(resp.Body)
			if err != nil {
				return errors.Wrap(err, "Error reading body from response of http get call")
			}
			fmt.Println(string(body))
			if resp.StatusCode != 200 {
				time.Sleep(time.Second * 10)
			} else {
				return nil
			}
		}
	}
}