I have written a code to send request to Github to get the files changed (added/modified) in a commit id. I am getting the response correctly. I am storing the file details in a slice. This is how I am doing it:
var allFiles []open_api.FilesMetaData
var fm open_api.FilesMetaData
for _, e := range file.Files {
fm = open_api.FilesMetaData {
FileName: &e.Filename,
Status: &e.Status,
}
allFiles = append(allFiles, fm)
}
Inside the for loop, I am parsing the github response and only taking the file name and its status and storing this struct into the slice allFiles. So the expected behaviour is all the files modified should be in the slice. However what I am finding is that the new value of fm is updating the existing values of the slice. I changed 3 files viz. cloudbuild.yaml , .gitignore and pom.xml but finally what I am getting in the slice is
[{"fileName": "pom.xml", "status": "modified"},{"fileName": "pom.xml", "status": "modified"},{"fileName": "pom.xml", "status": "modified"}] instead of [{"fileName": "pom.xml", "status": "modified"},{"fileName": ".gitignore", "status": "modified"},{"fileName": "cloudbuild.yaml", "status": "modified"}]
What's going on? I think I am missing some concept here!