github.com/vlifesystems/rulehunter@v0.0.0-20180501090014-673078aa4a83/html/tplreport.go (about)

     1  // Copyright (C) 2016-2017 vLife Systems Ltd <http://vlifesystems.com>
     2  // Licensed under an MIT licence.  Please see LICENSE.md for details.
     3  
     4  package html
     5  
     6  import (
     7  	"sort"
     8  	"time"
     9  
    10  	"github.com/vlifesystems/rulehunter/report"
    11  )
    12  
    13  type TplReport struct {
    14  	Mode        string
    15  	Title       string
    16  	Tags        map[string]string
    17  	Category    string
    18  	CategoryURL string
    19  	DateTime    string
    20  	Filename    string
    21  	Stamp       time.Time
    22  }
    23  
    24  func newTplReport(
    25  	mode report.ModeKind,
    26  	title string,
    27  	tags map[string]string,
    28  	category string,
    29  	categoryURL string,
    30  	filename string,
    31  	stamp time.Time,
    32  ) *TplReport {
    33  	return &TplReport{
    34  		Mode:        mode.String(),
    35  		Title:       title,
    36  		Tags:        tags,
    37  		Category:    category,
    38  		CategoryURL: categoryURL,
    39  		DateTime:    stamp.Format(time.RFC822),
    40  		Filename:    filename,
    41  		Stamp:       stamp,
    42  	}
    43  }
    44  
    45  // byDate implements sort.Interface for []*TplReport
    46  type byDate []*TplReport
    47  
    48  func (r byDate) Len() int { return len(r) }
    49  func (r byDate) Swap(i, j int) {
    50  	r[i], r[j] = r[j], r[i]
    51  }
    52  func (r byDate) Less(i, j int) bool {
    53  	return r[j].Stamp.Before(r[i].Stamp)
    54  }
    55  
    56  func sortTplReportsByDate(tplReports []*TplReport) {
    57  	sort.Sort(byDate(tplReports))
    58  }