How to avoid re-implementing sort.Interface for similar golang structs
问题 There is one problem bothering me in Golang. Say I have 2 structs: type Dog struct { Name string Breed string Age int } type Cat struct { Name string FavoriteFood string Age int } And when I try to sort []*Dog and []*Cat by Age , I have to define 2 different sort struct like: type SortCat []*Cat func (c SortCat) Len() int {//..} func (c SortCat) Swap(i, j int) {//..} func (c SortCat) Less(i, j int) bool {//..} type SortDog []*Dog func (c SortDog) Len() int {//..} func (c SortDog) Swap(i, j