func helperUpdateToken(moodle *InfoMoodle) errors.ErrorCode {
	resp, err := RequestAuthentication(moodle.URL, moodle.Username, moodle.Password)
	if err != nil {
		return errors.InternetError
	}

	// Check for error codes
	// Check if the request was unsuccessful
	if _, ok := resp["error"]; ok {
		return errors.ConvertMoodleError(resp["error"].(string))
	}

	if resp["token"].(string) == moodle.Token {
		// Something weird is going on
		return errors.MoodleError
	}

	// A new token exists
	moodle.Token = resp["token"].(string)
	err = SaveToken(moodle.URL, moodle.Username, moodle.Token)

	if err != nil {
		return errors.DBError
	}

	return errors.NoError
}
// helperUpdateToken Checks if the current moodle token is outdated, and updates
// it both in the DB and in the InfoMoodle struct. If it was successful returns
// a NoError. Otherwise it returns the corresponding error
helperUpdateToken Checks if the current moodle token is outdated, and updates
it both in the DB and in the InfoMoodle struct. If it was successful returns
a NoError. Otherwise it returns the corresponding error
// helperUpdateToken Checks if the current moodle token is outdated and updates // it both in the DB and in the InfoMoodle struct . If it was successful returns // a NoError . Otherwise it returns the corresponding error
func helperUpdateToken(moodle *InfoMoodle) errors.ErrorCode {
	resp, err := RequestAuthentication(moodle.URL, moodle.Username, moodle.Password)
	if err != nil {
		return errors.InternetError
	}
	if _, ok := resp["error"]; ok {
		return errors.ConvertMoodleError(resp["error"].(string))
	}
	if resp["token"].(string) == moodle.Token {
		return errors.MoodleError
	}
	moodle.Token = resp["token"].(string)
	err = SaveToken(moodle.URL, moodle.Username, moodle.Token)
	if err != nil {
		return errors.DBError
	}
	return errors.NoError
}
func helperUpdateToken ( moodle * InfoMoodle ) errors . ErrorCode { resp , err := RequestAuthentication ( moodle . URL , moodle . Username , moodle . Password ) if err != nil { return errors . InternetError } if _ , ok := resp [ " " ] ; ok { return errors . ConvertMoodleError ( resp [ " " ] . ( string ) ) } if resp [ " " ] . ( string ) == moodle . Token { return errors . MoodleError } moodle . Token = resp [ " " ] . ( string ) err = SaveToken ( moodle . URL , moodle . Username , moodle . Token ) if err != nil { return errors . DBError } return errors . NoError }
helperUpdateToken Checks if the current moodle token is outdated, and updates
it both in the DB and in the InfoMoodle struct.
helperUpdateToken Checks if the current moodle token is outdated and updates it both in the DB and in the InfoMoodle struct .
// Check for error codes // Check if the request was unsuccessful // Something weird is going on // A new token exists