From 9f141b4a31c5c94275d5010cc92e9631237ab0d8 Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Mon, 13 May 2019 22:43:45 -0400 Subject: recording user addition date in time.Time and RFC3339 --- cache/index.go | 11 ++++++++++- cache/types.go | 8 +++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cache/index.go b/cache/index.go index e0a3dd0..641e6dc 100644 --- a/cache/index.go +++ b/cache/index.go @@ -1,5 +1,10 @@ package cache +import ( + "log" + "time" +) + // NewUserIndex returns a new instance of a user index func NewUserIndex() *UserIndex { return &UserIndex{} @@ -7,8 +12,12 @@ func NewUserIndex() *UserIndex { // AddUser inserts a new user into the index. The *Data struct only contains the nickname.) func (index UserIndex) AddUser(nick string, url string) { + rfc3339date, err := time.Now().MarshalText() + if err != nil { + log.Printf("Error formatting user add time as RFC3339: %v\n", err) + } imutex.Lock() - index[url] = &Data{nick: nick} + index[url] = &Data{nick: nick, date: time.Now(), apidate: rfc3339date} imutex.Unlock() } diff --git a/cache/types.go b/cache/types.go index 8f364d5..ed270c3 100644 --- a/cache/types.go +++ b/cache/types.go @@ -2,6 +2,7 @@ package cache import ( "sync" + "time" ) // Indexer allows for other uses of the Index functions @@ -15,9 +16,10 @@ type UserIndex map[string]*Data // Data from user's twtxt.txt type Data struct { - nick string - url string - status []string + nick string + date time.Time + apidate []byte + status []string } // Mutex to control access to the User Index -- cgit 1.4.1-2-gfad0