jjzjj

go - 在具有基础字段的任何结构数组上调用方法

假设我有一堆结构(大约10个)。typeAstruct{IDint64...otherA-specificfields}typeBstruct{IDint64...otherB-specificfields}typeCstruct{IDint64...otherC-specificfields}如果我在任何给定时间有这些结构的数组([]A、[]B或[]C),我如何编写一个函数来从结构数组中提取ID而无需编写3个(或者在我的情况下为10个)单独的函数,如下所示:typeAList[]AtypeBList[]BtypeCList[]Cfunc(list*AList)GetIDs()[]in

go - 在具有基础字段的任何结构数组上调用方法

假设我有一堆结构(大约10个)。typeAstruct{IDint64...otherA-specificfields}typeBstruct{IDint64...otherB-specificfields}typeCstruct{IDint64...otherC-specificfields}如果我在任何给定时间有这些结构的数组([]A、[]B或[]C),我如何编写一个函数来从结构数组中提取ID而无需编写3个(或者在我的情况下为10个)单独的函数,如下所示:typeAList[]AtypeBList[]BtypeCList[]Cfunc(list*AList)GetIDs()[]in