// FetchMetadata fetches the metadata (manifests and descriptions) from a remote server
FetchMetadata fetches the metadata (manifests and descriptions) from a remote server
// FetchMetadata fetches the metadata ( manifests and descriptions ) from a remote server
func FetchMetadata(serverAddr, serverPath, localPath string) error {
	if _, err := os.Stat(localPath); err != nil {
		if err := os.Mkdir(localPath, 0755); err != nil {
			return fmt.Errorf("Failed to create directory for local data '%v': %v", localPath, err)
		}
	}
	log.Info("Requesting data for ", serverPath)
	resp, err := http.Get(serverAddr + serverPath)
	if err != nil {
		log.Error("HTTP request failed: ", err)
		return err
	}
	defer resp.Body.Close()
	log.Debug("Response Status: ", resp.Status)
	if resp.StatusCode != 200 {
		log.Warn("Request returned error - ", resp.Status)
		return err
	}
	content, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		log.Error("Failed to read response")
		return err
	}
	log.Trace("Content:\n", string(content))
	var pre Pre
	err = xml.Unmarshal(content, &pre)
	if err != nil {
		log.Error("Error Unmarshalling - ", err)
		return err
	}
	err = fetchDataRecursively(pre, serverAddr, serverPath, localPath)
	if err != nil {
		log.Error("Error saving data - ", err)
		return err
	}
	return nil
}
func FetchMetadata ( serverAddr , serverPath , localPath string ) error { if _ , err := os . Stat ( localPath ) ; err != nil { if err := os . Mkdir ( localPath , 0755 ) ; err != nil { return fmt . Errorf ( " " , localPath , err ) } } log . Info ( " " , serverPath ) resp , err := http . Get ( serverAddr + serverPath ) if err != nil { log . Error ( " " , err ) return err } defer resp . Body . Close ( ) log . Debug ( " " , resp . Status ) if resp . StatusCode != 200 { log . Warn ( " " , resp . Status ) return err } content , err := ioutil . ReadAll ( resp . Body ) if err != nil { log . Error ( " " ) return err } log . Trace ( " \n " , string ( content ) ) var pre Pre err = xml . Unmarshal ( content , & pre ) if err != nil { log . Error ( " " , err ) return err } err = fetchDataRecursively ( pre , serverAddr , serverPath , localPath ) if err != nil { log . Error ( " " , err ) return err } return nil }
FetchMetadata fetches the metadata (manifests and descriptions) from a remote server
FetchMetadata fetches the metadata ( manifests and descriptions ) from a remote server
// Create local path // Read file root directory // Parse root directory // Parse subdirectories recursively and save files