Skip to content

Commit f01ae75

Browse files
committed
added topick
1 parent a3bbf37 commit f01ae75

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

memory_retention.go

+37
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ var mutex = &sync.Mutex{}
1111
// - Key is a hash value that identifies an individual.
1212
var data = make(map[string][]string)
1313

14+
// Topics specified by the presenter.
15+
var topics = make(map[string]string)
16+
1417
// Save whether the key is in use.
1518
// If the key does not exist in this map, it is not used.
1619
var keyMap = make(map[string]bool)
@@ -109,3 +112,37 @@ func GetAnswer(key string) ([]string, error) {
109112

110113
return answer, nil
111114
}
115+
116+
// Set a topic.
117+
//
118+
// Arguments:
119+
// key {string} - Key value.
120+
// value {string} - topic
121+
func SetTopic(key string, value string) error {
122+
mutex.Lock()
123+
if err := exist(key); err != nil {
124+
return err
125+
}
126+
topics[key] = value
127+
mutex.Unlock()
128+
129+
return nil
130+
}
131+
132+
// Get topic
133+
//
134+
// Arguments:
135+
// key {string} - key value.
136+
//
137+
// Returns:
138+
// {string} - topic.
139+
func GetTopic(key string) (string, error) {
140+
mutex.Lock()
141+
if err := exist(key); err != nil {
142+
return "", err
143+
}
144+
topic := topics[key]
145+
mutex.Unlock()
146+
147+
return topic, nil
148+
}

0 commit comments

Comments
 (0)