Advertisement
Guest User

item.go

a guest
Aug 8th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.53 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "html/template"
  5.     "time"
  6. )
  7.  
  8. // Item is RSS entry which goes to template rendering
  9. type Item struct {
  10.     Author  string
  11.     Title   string
  12.     Link    string
  13.     Date    time.Time
  14.     Content template.HTML
  15. }
  16.  
  17. // ItemSlice is slice of Item type implementing Sort interface
  18. type ItemSlice []Item
  19.  
  20. func (its ItemSlice) Len() int {
  21.     return len(its)
  22. }
  23.  
  24. func (its ItemSlice) Less(i, j int) bool {
  25.     return its[j].Date.Before(its[i].Date)
  26. }
  27.  
  28. func (its ItemSlice) Swap(i, j int) {
  29.     its[i], its[j] = its[j], its[i]
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement