From 8af4945c9841b23224c6f76460278f67947fd01e Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Mon, 13 May 2019 04:27:31 -0400 Subject: separating cache into its own library --- cache/index.go | 20 ++++++++++++++++++++ cache/types.go | 24 ++++++++++++++++++++++++ types.go | 4 ++-- 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 cache/index.go create mode 100644 cache/types.go diff --git a/cache/index.go b/cache/index.go new file mode 100644 index 0000000..e0a3dd0 --- /dev/null +++ b/cache/index.go @@ -0,0 +1,20 @@ +package cache + +// NewUserIndex returns a new instance of a user index +func NewUserIndex() *UserIndex { + return &UserIndex{} +} + +// AddUser inserts a new user into the index. The *Data struct only contains the nickname.) +func (index UserIndex) AddUser(nick string, url string) { + imutex.Lock() + index[url] = &Data{nick: nick} + imutex.Unlock() +} + +// DelUser removes a user from the index completely. +func (index UserIndex) DelUser(url string) { + imutex.Lock() + delete(index, url) + imutex.Unlock() +} diff --git a/cache/types.go b/cache/types.go new file mode 100644 index 0000000..8f364d5 --- /dev/null +++ b/cache/types.go @@ -0,0 +1,24 @@ +package cache + +import ( + "sync" +) + +// 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 + url string + status []string +} + +// Mutex to control access to the User Index +var imutex = sync.RWMutex{} diff --git a/types.go b/types.go index 8e924ca..35f70b3 100644 --- a/types.go +++ b/types.go @@ -11,11 +11,11 @@ type configuration struct { stdoutLogging bool instance } + +// refers to this specific instance of getwtxt type instance struct { name string url string owner string mail string } - -// index of users -- cgit 1.4.1-2-gfad0