Lint models/release.go

This commit is contained in:
Bwko 2016-11-24 22:02:54 +01:00
parent 21e8deed89
commit ece19f4a5e

View File

@ -38,12 +38,14 @@ type Release struct {
CreatedUnix int64
}
// BeforeInsert is invoked from XORM before inserting an object of this type.
func (r *Release) BeforeInsert() {
if r.CreatedUnix == 0 {
r.CreatedUnix = time.Now().Unix()
}
}
// AfterSet is invoked from XORM after setting the value of a field of this object.
func (r *Release) AfterSet(colName string, _ xorm.Cell) {
switch colName {
case "created_unix":
@ -151,15 +153,15 @@ func GetReleasesByRepoID(repoID int64, page, pageSize int) (rels []*Release, err
return rels, err
}
type ReleaseSorter struct {
type releaseSorter struct {
rels []*Release
}
func (rs *ReleaseSorter) Len() int {
func (rs *releaseSorter) Len() int {
return len(rs.rels)
}
func (rs *ReleaseSorter) Less(i, j int) bool {
func (rs *releaseSorter) Less(i, j int) bool {
diffNum := rs.rels[i].NumCommits - rs.rels[j].NumCommits
if diffNum != 0 {
return diffNum > 0
@ -167,13 +169,13 @@ func (rs *ReleaseSorter) Less(i, j int) bool {
return rs.rels[i].Created.After(rs.rels[j].Created)
}
func (rs *ReleaseSorter) Swap(i, j int) {
func (rs *releaseSorter) Swap(i, j int) {
rs.rels[i], rs.rels[j] = rs.rels[j], rs.rels[i]
}
// SortReleases sorts releases by number of commits and created time.
func SortReleases(rels []*Release) {
sorter := &ReleaseSorter{rels: rels}
sorter := &releaseSorter{rels: rels}
sort.Sort(sorter)
}