-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcache.go
More file actions
43 lines (33 loc) · 655 Bytes
/
cache.go
File metadata and controls
43 lines (33 loc) · 655 Bytes
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
package main
import (
"regexp"
)
type Record struct {
ip string
arpa string
fqdn string
}
type Cache struct {
records map[string]*Record
}
func (c Cache) Set(id string, r *Record) {
c.records[id] = r
}
// Provides lookups based on fqdn or ip
func (c Cache) Get(id string) (*Record, bool) {
var reverseLookup = regexp.MustCompile("^.*\\.in-addr\\.arpa\\.$")
if reverseLookup.MatchString(id) {
for _, record := range c.records {
if record.arpa == id {
return record, true
}
}
}
if record, ok := c.records[id]; ok {
return record, true
}
return nil, false
}
func (c Cache) Remove(id string) {
delete(c.records, id)
}