summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-05-13 04:27:31 -0400
committerBen Morrison <ben@gbmor.dev>2019-05-13 04:27:31 -0400
commit8af4945c9841b23224c6f76460278f67947fd01e (patch)
tree87ed7244030e66d5afa0bf307d1b94f4c09b85eb
parentf06a2d6126bed22d38b506e1edc8822386a7cc33 (diff)
downloadgetwtxt-8af4945c9841b23224c6f76460278f67947fd01e.tar.gz
separating cache into its own library
-rw-r--r--cache/index.go20
-rw-r--r--cache/types.go24
-rw-r--r--types.go4
3 files changed, 46 insertions, 2 deletions
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
Agaram <vc@akkartik.com> 2018-06-30 21:57:49 -0700 4292 - start a Vim syntax file for our 'language'' href='/akkartik/mu/commit/subx/subx.vim?h=hlt&id=2c6a077f2913d7f04382b8d06760552606a64ac8'>2c6a077f ^
1837c616 ^
a0db7903 ^
c2532c2d ^
76aace46 ^
e59a91b7 ^
39d718af ^

a8f47b4a ^
c6f52200 ^


e59a91b7 ^
39d718af ^
3fb900de ^
50a6c048 ^
3fb900de ^
39d718af ^
3fb900de ^
39d718af ^
cbe5bec6 ^
39d718af ^
9272b6ce ^

521ff2f1 ^
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75