func DownloadAzertiFile(url string) *AzertiCatalog {
list := AzertiCatalog{}
ftpClient, err := ftp.Dial(globals.GlobalSettings.FtpAddress)
defer ftpClient.Quit()
err = ftpClient.Login(globals.GlobalSettings.FtpUser, globals.GlobalSettings.FtpPassword)
err = ftpClient.ChangeDir("/U17-user/")
resp, _ := ftpClient.Retr(url)
body, err := ioutil.ReadAll(resp)
if err != nil {
return &list
}
newbody := strings.Replace(string(body), "<offers>", "", -1)
newbody = strings.Replace(newbody, "</offers>", "", -1)
err = xml.Unmarshal([]byte(newbody), &list)
if err != nil {
return &list
}
return &list
}
func DownloadAzertiFile(url string) *AzertiCatalog {
list := AzertiCatalog{}
ftpClient, err := ftp.Dial(globals.GlobalSettings.FtpAddress)
defer ftpClient.Quit()
err = ftpClient.Login(globals.GlobalSettings.FtpUser, globals.GlobalSettings.FtpPassword)
err = ftpClient.ChangeDir("/U17-user/") // файл находится тут
resp, _ := ftpClient.Retr(url)
fmt.Println(resp)
// Open our xmlFile
xmlFile, err := os.Open(url) // сюда должен передать польный путь к файлу
// if we os.Open returns an error then handle it
if err != nil {
fmt.Println(err)
}
fmt.Println("Successfully Opened import.xml")
// defer the closing of our xmlFile so that we can parse it later on
defer xmlFile.Close()
// read our opened xmlFile as a byte array.
body, _ := ioutil.ReadAll(xmlFile)
if err != nil {
return &list
}
newbody := strings.Replace(string(body), "<offers>", "", -1)
newbody = strings.Replace(newbody, "</offers>", "", -1)
err = xml.Unmarshal([]byte(newbody), &list)
if err != nil {
return &list
}
return &list
}