What would be the best approach to create a modular function that abstracts structs that represent different API calls instead of creating 7 different methods that do exactly the sme thing like I do here ?
func (s *ServiceJob) findNewCityData(apiData []structs.City, tableData map[int]struct{}) []structs.City {
var newData []structs.City
for _, a := range apiData {
if _, exists := tableData[a.CityID]; !exists {
newData = append(newData, a)
}
}
return newData
}
func (s *ServiceJob) findNewCountryData(apiData []structs.Country, tableData map[int]struct{}) []structs.Country {
var newData []structs.Country
for _, a := range apiData {
if _, exists := tableData[a.CountryIsoNumeric]; !exists {
newData = append(newData, a)
}
}
return newData
}
Generic fucntion ?