summary refs log tree commit diff stats
path: root/cache/types.go
blob: 939114ea9f54720b3bd1fd3f6a7faeef1fdec0fb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package cache

import (
	"sync"
	"time"
)

// Indexer allows for other uses of the Index functions
type Indexer interface {
	AddUser(string, string)
	DelUser(string)
}

// UserIndex provides an index of users by URL
type UserIndex map[string]*Data

// Data from user's twtxt.txt
type Data struct {
	nick    string
	date    time.Time
	apidate []byte
	status  []string
}

// Mutex to control access to the User Index.
var imutex = sync.RWMutex{}

// TimeSlice is used for sorting by timestamp.
type TimeSlice []time.Time

// Len returns the length of the slice to be sorted.
// This helps satisfy sort.Interface with respect to TimeSlice.
func (t TimeSlice) Len() int {
	return len(t)
}

// Less returns true if the timestamp at index i is before the timestamp at index j in TimeSlice.
// This helps satisfy sort.Interface with respect to TimeSlice.
func (t TimeSlice) Less(i, j int) bool {
	return t[i].Before(t[j])
}

// Swap transposes the timestampss at the two given indices.
// This helps satisfy sort.Interface with respect to TimeSlice.
func (t TimeSlice) Swap(i, j int) {
	t[i], t[j] = t[j], t[i]
}