获取用户列表,按照申请时间倒序排序,注:调用标准库的sort.Sort必须要先实现Len(),Less(),Swap() 三个方法.
......
import (
"fmt"
"io/ioutil"
"sort"
"time"
)
type User struct {
ApplicantGuid string `json:"applicant_guid"`
ApplyTime string `json:"apply_time"`
UsedLicense int `json:"used_license"`
Applicant string `json:"applicant"`
}
type newUserList []User
func (I newUserList) Len() int {
return len(I)
}
func (I newUserList) Less(i, j int) bool {
return stringConvertTime(I[i].ApplyTime) > stringConvertTime(I[j].ApplyTime)
}
func (I newUserList) Swap(i, j int) {
I[i], I[j] = I[j], I[i]
}
例如对user_list进行排序:
TestData["license_detail"] = `{
......
import (
"fmt"
"io/ioutil"
"sort"
"time"
)
type User struct {
ApplicantGuid string `json:"applicant_guid"`
ApplyTime string `json:"apply_time"`
UsedLicense int `json:"used_license"`
Applicant string `json:"applicant"`
}
type newUserList []User
func (I newUserList) Len() int {
return len(I)
}
func (I newUserList) Less(i, j int) bool {
return stringConvertTime(I[i].ApplyTime) > stringConvertTime(I[j].ApplyTime)
}
func (I newUserList) Swap(i, j int) {
I[i], I[j] = I[j], I[i]
}
例如对user_list进行排序:
TestData["license_detail"] = `{