Sorting Golang Sort:未实现Sort.Interface(缺少Len方法)

Sorting Golang Sort:未实现Sort.Interface(缺少Len方法),sorting,go,Sorting,Go,我在Go应用程序中实现排序接口时遇到问题。以下是相关代码: type Group struct { Teams []*Team } type Team struct { Points int } type Teams []*Team func (slice Teams) Len() int { return len(slice) } func (slice Te

我在Go应用程序中实现排序接口时遇到问题。以下是相关代码:

type Group struct {
   Teams []*Team
}

type Team struct {
    Points int
 }

    type Teams []*Team

            func (slice Teams) Len() int {
                return len(slice)
            }

            func (slice Teams) Less(i, j int) bool {
                return slice[i].Points < slice[j].Points
            }

            func (slice Teams) Swap(i, j int) {
                slice[i], slice[j] = slice[j], slice[i]
            }
我得到这个错误:

 cannot use group.Teams (type []*Team) as type sort.Interface in argument
to sort.Sort:   []*Team does not implement sort.Interface (missing Len
method)
为什么会这样?

[]*团队与团队不同;您需要显式使用或强制转换到后者:

type Group struct {
   Teams Teams
}
sort.Sort(group.Teams)
或:

[]*团队与团队不同;您需要显式使用或强制转换到后者:

type Group struct {
   Teams Teams
}
sort.Sort(group.Teams)
或:

type Group struct {
   Teams []*Team
}
sort.Sort(Teams(group.Teams))