// GetUserFromDataStore gets a user from the datastore service
// 		userFromDataStore, err := GetUserFromDataStore(steamID)
GetUserFromDataStore gets a user from the datastore service
userFromDataStore, err := GetUserFromDataStore(steamID)
// GetUserFromDataStore gets a user from the datastore service // userFromDataStore err : = GetUserFromDataStore ( steamID )
func (control Cntr) GetUserFromDataStore(steamID string) (common.UserDocument, error) {
	targetURL := fmt.Sprintf("http://%s/api/getuser/%s", os.Getenv("DATASTORE_INSTANCE"), steamID)
	req, err := http.NewRequest("GET", targetURL, nil)
	if err != nil {
		return common.UserDocument{}, err
	}
	req.Close = true
	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Authentication", os.Getenv("AUTH_KEY"))
	client := &http.Client{}
	maxRetryCount := 3
	successfulRequest := false
	res, err := client.Do(req)
	if err != nil || res.StatusCode != http.StatusOK {
		logMsg := fmt.Sprintf("error from first call to getuser (%s), retrying now", targetURL)
		configuration.Logger.Info(logMsg,
			zap.String("errorMsg", fmt.Sprint(err)),
			zap.String("request", fmt.Sprintf("%+v", res)),
			zap.String("response", fmt.Sprintf("%+v", req)))
		for i := 0; i < maxRetryCount; i++ {
			res, err = client.Do(req)
			if err == nil && res.StatusCode == http.StatusOK {
				successfulRequest = true
				defer res.Body.Close()
				break
			}
			exponentialBackOffSleepTime := math.Pow(2, float64(i)) * 16
			configuration.Logger.Sugar().Infof("failed to call %s for %s %d times. Sleeping for %d ms", targetURL, steamID, i, exponentialBackOffSleepTime)
			time.Sleep(time.Duration(exponentialBackOffSleepTime) * time.Millisecond)
		}
	} else {
		successfulRequest = true
	}
	if !successfulRequest {
		failedAllRetriesErr := fmt.Errorf("failed all retries to %s for steamID: %s", targetURL, steamID)
		return common.UserDocument{}, commonUtil.MakeErr(failedAllRetriesErr)
	}
	body, err := ioutil.ReadAll(res.Body)
	if err != nil {
		return common.UserDocument{}, commonUtil.MakeErr(err, "failed to readall for getUser body")
	}
	userDoc := dtos.GetUserDTO{}
	err = json.Unmarshal(body, &userDoc)
	if err != nil {
		return common.UserDocument{}, commonUtil.MakeErr(err, fmt.Sprintf("failed to unmarshal getUser object: %+v", string(body)))
	}
	return userDoc.User, nil
}
func ( control Cntr ) GetUserFromDataStore ( steamID string ) ( common . UserDocument , error ) { targetURL := fmt . Sprintf ( " " , os . Getenv ( " " ) , steamID ) req , err := http . NewRequest ( " " , targetURL , nil ) if err != nil { return common . UserDocument { } , err } req . Close = true req . Header . Set ( " " , " " ) req . Header . Set ( " " , os . Getenv ( " " ) ) client := & http . Client { } maxRetryCount := 3 successfulRequest := false res , err := client . Do ( req ) if err != nil || res . StatusCode != http . StatusOK { logMsg := fmt . Sprintf ( " " , targetURL ) configuration . Logger . Info ( logMsg , zap . String ( " " , fmt . Sprint ( err ) ) , zap . String ( " " , fmt . Sprintf ( " " , res ) ) , zap . String ( " " , fmt . Sprintf ( " " , req ) ) ) for i := 0 ; i < maxRetryCount ; i ++ { res , err = client . Do ( req ) if err == nil && res . StatusCode == http . StatusOK { successfulRequest = true defer res . Body . Close ( ) break } exponentialBackOffSleepTime := math . Pow ( 2 , float64 ( i ) ) * 16 configuration . Logger . Sugar ( ) . Infof ( " " , targetURL , steamID , i , exponentialBackOffSleepTime ) time . Sleep ( time . Duration ( exponentialBackOffSleepTime ) * time . Millisecond ) } } else { successfulRequest = true } if ! successfulRequest { failedAllRetriesErr := fmt . Errorf ( " " , targetURL , steamID ) return common . UserDocument { } , commonUtil . MakeErr ( failedAllRetriesErr ) } body , err := ioutil . ReadAll ( res . Body ) if err != nil { return common . UserDocument { } , commonUtil . MakeErr ( err , " " ) } userDoc := dtos . GetUserDTO { } err = json . Unmarshal ( body , & userDoc ) if err != nil { return common . UserDocument { } , commonUtil . MakeErr ( err , fmt . Sprintf ( " " , string ( body ) ) ) } return userDoc . User , nil }
GetUserFromDataStore gets a user from the datastore service
userFromDataStore, err := GetUserFromDataStore(steamID)
GetUserFromDataStore gets a user from the datastore service userFromDataStore err : = GetUserFromDataStore ( steamID )
// Failed after all retries