// StartAnalyzing - send the request to the foremast service to start the job
send the request to the foremast service to start the job
// StartAnalyzing - send the request to the foremast service to start the job
func StartAnalyzing(analyzingRequest ApplicationHealthAnalyzeRequest) (string, error) {
	endpoint := os.Getenv("FOREMAST_SERVICE_ENDPOINT") + "/v1/healthcheck/create"
	c, err := NewClient(nil, endpoint)
	if err != nil {
		log.Printf("[%s] error creating client: %#v\n %s\n", analyzingRequest.AppName, err, err.Error())
		return "", err
	}
	b, err := json.Marshal(analyzingRequest)
	if err != nil {
		return "", err
	}
	rel := &url.URL{Path: "create"}
	u := c.BaseURL.ResolveReference(rel)
	log.Printf("[%s] Request body: %#v\n", analyzingRequest.AppName, string(b))
	req, err := http.NewRequest("POST", endpoint, bytes.NewReader(b))
	if err != nil {
		return "", err
	}
	req.Header.Set("Accept", "application/json")
	req.Header.Set("User-Agent", c.UserAgent)
	resp, err := c.HttpClient.Do(req)
	if err != nil {
		log.Printf("[%s] request err: %#v\n %s\n", analyzingRequest.AppName, err, err.Error())
		return "", err
	}
	if resp.StatusCode != 200 {
		return "", errors.NewBadRequest(u.String() + " responded invalid server response:" + resp.Status)
	}
	defer resp.Body.Close()
	var analyzingResponse = ApplicationHealthAnalyzeResponse{}
	err = json.NewDecoder(resp.Body).Decode(&analyzingResponse)
	if err != nil {
		return "", err
	}
	if analyzingResponse.JobId == "" {
		return "", errors.NewBadRequest(u.String() + " responded invalid server response:" + analyzingResponse.Reason)
	}
	return analyzingResponse.JobId, nil
}
func StartAnalyzing ( analyzingRequest ApplicationHealthAnalyzeRequest ) ( string , error ) { endpoint := os . Getenv ( " " ) + " " c , err := NewClient ( nil , endpoint ) if err != nil { log . Printf ( " \n \n " , analyzingRequest . AppName , err , err . Error ( ) ) return " " , err } b , err := json . Marshal ( analyzingRequest ) if err != nil { return " " , err } rel := & url . URL { Path : " " } u := c . BaseURL . ResolveReference ( rel ) log . Printf ( " \n " , analyzingRequest . AppName , string ( b ) ) req , err := http . NewRequest ( " " , endpoint , bytes . NewReader ( b ) ) if err != nil { return " " , err } req . Header . Set ( " " , " " ) req . Header . Set ( " " , c . UserAgent ) resp , err := c . HttpClient . Do ( req ) if err != nil { log . Printf ( " \n \n " , analyzingRequest . AppName , err , err . Error ( ) ) return " " , err } if resp . StatusCode != 200 { return " " , errors . NewBadRequest ( u . String ( ) + " " + resp . Status ) } defer resp . Body . Close ( ) var analyzingResponse = ApplicationHealthAnalyzeResponse { } err = json . NewDecoder ( resp . Body ) . Decode ( & analyzingResponse ) if err != nil { return " " , err } if analyzingResponse . JobId == " " { return " " , errors . NewBadRequest ( u . String ( ) + " " + analyzingResponse . Reason ) } return analyzingResponse . JobId , nil }
send the request to the foremast service to start the job
send the request to the foremast service to start the job