-
Notifications
You must be signed in to change notification settings - Fork 3
/
gc.go
46 lines (40 loc) · 918 Bytes
/
gc.go
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
package main
import (
"net/http"
"sync"
"time"
)
func cleanDB(db *sync.Map) {
for {
// sleep inside infinite loop
time.Sleep(15 * time.Second)
// range over db
db.Range(func(key interface{}, val interface{}) bool {
// cast key to string
if id, ok := key.(string); ok {
// cast value to challenge record
if record, ok := val.(challengeDBRecord); ok {
// check expiration time
if record.Expires.Before(time.Now()) {
Debug.Printf(
"%d, Domain:'%s', ID:'%s', %s\n",
http.StatusOK, record.Domain,
id, messageExpiredRecord,
)
// check then id is NOT UUID
if !reUUID.MatchString(id) {
Bot.Printf(
"%d, Domain:'%s', Addr:'%s', UA:'%s'\n",
http.StatusTeapot, record.Domain,
record.Address, record.UserAgent,
)
}
// delete key
db.Delete(key)
}
}
}
return true
})
}
}