func getRequestBackoff(hostname string) chan RequestResult {
	requestResultChan := make(chan RequestResult)
	go func() {
		defer close(requestResultChan)
		requestResult := RequestResult{}
		retrySleep := func(t int) {
			log.Infoln("Retrying in", t*5, "seconds.")
			time.Sleep(time.Duration(t) * 5 * time.Second)
		}
		attempts := 1
		maxRetries := 10
		log.Infoln("Beginning backoff loop for HTTP", http.MethodGet, "request.")
		err := errors.New("")  
		for err != nil {       
			if attempts > maxRetries {
				log.Infoln("Could not successfully make an HTTP request after", attempts, "attempts.")
				requestResult.Err = err
				requestResultChan <- requestResult
				return
			}
			log.Debugln("Making", http.MethodGet, "to", hostname)
			var resp *http.Response
			resp, err = http.Get(hostname)
			if err == nil && resp.StatusCode == http.StatusOK {
				log.Infoln("Successfully made an HTTP request on attempt:", attempts)
				log.Infoln("Got a", resp.StatusCode, "with a", http.MethodGet, "to", hostname)
				closeErr := resp.Body.Close()
				if closeErr != nil {
					log.Debugln("Failed to close response body:", closeErr.Error())
				}
				requestResult.Response = resp
				requestResultChan <- requestResult
				return
			}
			if err != nil && !strings.Contains(err.Error(), "no such host") {
				log.Debugln("An error occurred making a", http.MethodGet, "request:", err)
			}
			if resp != nil {
				log.Debugln("Got a", resp.StatusCode)
				closeErr := resp.Body.Close()
				if closeErr != nil {
					log.Debugln("Failed to close response body:", closeErr.Error())
				}
			}
			retrySleep(attempts)
			attempts++
		}
		if err != nil {
			log.Errorln("Could not make a", http.MethodGet, "request to", hostname, "due to:", err.Error())
			requestResult.Err = fmt.Errorf("failed to hit endpoint after backoff loop: %w", err)
		}
		requestResultChan <- requestResult
		return
	}()
	return requestResultChan
}
getRequestBackoff returns a channel that reports the result of a GET backoff loop from the hostname endpoint.
package main
import (
	"context"
	"errors"
	"fmt"
	"net/http"
	"strings"
	"time"
	log "github.com/sirupsen/logrus"
)
type RequestResult struct {
	Response *http.Response
	Err      error
}
func makeRequestToDeploymentCheckService(ctx context.Context, hostname string) chan error {
	requestChan := make(chan error)
	go func() {
		log.Infoln("Looking for a response from the endpoint.")
		backoffTimeout := time.Minute * 3
		timeoutChan := time.After(backoffTimeout)
		log.Debugln("Setting timeout for backoff loop to:", backoffTimeout)
		defer close(requestChan)
		if len(hostname) == 0 {
			err := fmt.Errorf("given blank hostname for service load balancer endpoint -- skipping HTTP call")
			requestChan <- err
			return
		}
		if !strings.HasPrefix(hostname, "http://") {
			hostname = "http://" + hostname
		}
		select {
		case result := <-getRequestBackoff(hostname):
			if &result == nil {
				requestChan <- errors.New("got a nil request result from the backoff process")
				return
			}
			if result.Err != nil {
				requestChan <- result.Err
				return
			}
			if result.Response == nil {
				err := fmt.Errorf("could not get a response from the given address: %s", hostname)
				requestChan <- err
				return
			}
			if result.Response.StatusCode != http.StatusOK {
				requestChan <- result.Err
				return
			}
			log.Infoln("Got a result from", http.MethodGet, "request backoff:", result.Response.Status)
			requestChan <- nil
		case <-timeoutChan:
			log.Errorln("Backoff loop for a 200 response took too long and timed out.")
			err := cleanUp(ctx)
			if err != nil {
				err = fmt.Errorf("failed to clean up properly: %w", err)
			}
			requestChan <- err
		case <-ctx.Done():
			log.Errorln("Context expired while waiting for a", http.StatusOK, "from "+hostname+".")
			err := cleanUp(ctx)
			if err != nil {
				err = fmt.Errorf("failed to clean up properly: %w", err)
			}
			requestChan <- err
		}
	}()
	return requestChan
}