mirror of
https://github.com/hacdias/webdav.git
synced 2026-09-25 12:41:54 +08:00
feat: add source request log (#71)
Co-authored-by: shenyuning <[email protected]> Co-authored-by: sxueck <[email protected]>
This commit is contained in:
co-authored by
shenyuning
sxueck
parent
099479a894
commit
9a4b378b32
+31
@@ -0,0 +1,31 @@
|
||||
package lib
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
// map[reqHost:username]lastRequestSuccessTime
|
||||
var authorizedSource = make(map[string]time.Time, 1)
|
||||
|
||||
func LastRequestLogIndex(ctx context.Context) {
|
||||
updateInterval := 5 * time.Second
|
||||
ticker := time.NewTicker(updateInterval)
|
||||
for {
|
||||
ticker.Reset(updateInterval)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
log.Println("received a signal to cancel the service")
|
||||
return
|
||||
case <-ticker.C:
|
||||
for v, k := range authorizedSource {
|
||||
// no response for 2 minutes log again
|
||||
if k.Unix()+(60*2) < time.Now().Unix() {
|
||||
log.Printf("%s cache will be clean\n", v)
|
||||
delete(authorizedSource, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user