实现自定义排序规则
定义一个结构体及计算其length
的函数:
type Track struct {
Title string
Artist string
Album string
Year int
Length time.Duration
}
func length(s string) time.Duration {
d, err := time.ParseDuration(s)
if err != nil {
panic(s)
}
return d
}
样例数据如下:
var tracks = []*Track {
{
"Go", "Delilah", "From the Roots Up", 2012, length("3m38s")},
{
"Go", "Moby", "Moby", 1992, length("3m37s")},
{
"Go Ahead", "Alicia Keys", "As I Am", 2007, length("4m36s