diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-05-14 02:55:40 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-05-14 02:55:40 -0400 |
commit | a8ba50b53f45e06af03f5ef98e759539394a3c0c (patch) | |
tree | a5bfb512d6fcd208e2d050d9f06406e48d9c9185 /registry/types.go | |
parent | 7728f92e4f4b00d617ece97d9c6a88125821d874 (diff) | |
download | getwtxt-a8ba50b53f45e06af03f5ef98e759539394a3c0c.tar.gz |
package cache renamed to package registry
Diffstat (limited to 'registry/types.go')
-rw-r--r-- | registry/types.go | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/registry/types.go b/registry/types.go new file mode 100644 index 0000000..d3e421a --- /dev/null +++ b/registry/types.go @@ -0,0 +1,56 @@ +package registry + +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 StatusMap +} + +// StatusMap holds the statuses posted by a given user. A standard +// time.Time value is used as the key, with the status as a string. +type StatusMap map[time.Time]string + +// StatusMapSlice is a slice of StatusMaps. Useful for sorting the +// output of queries. +type StatusMapSlice []StatusMap + +// 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] +} |