File tree Expand file tree Collapse file tree 1 file changed +8
-9
lines changed
Expand file tree Collapse file tree 1 file changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -40,13 +40,13 @@ func (c *OnlineMap) AddIP(ip string) {
4040 if ip == "127.0.0.1" {
4141 return
4242 }
43+
4344 c .access .Lock ()
44- if _ , ok := c .ipList [ip ]; ! ok {
45- c .ipList [ip ] = time .Now ()
46- }
45+ c .ipList [ip ] = time .Now ()
4746 c .access .Unlock ()
47+
4848 if time .Since (c .lastCleanup ) > c .cleanupPeriod {
49- c .RemoveExpiredIPs (c . ipList )
49+ c .RemoveExpiredIPs ()
5050 c .lastCleanup = time .Now ()
5151 }
5252}
@@ -62,23 +62,22 @@ func (c *OnlineMap) GetKeys() []string {
6262 return keys
6363}
6464
65- func (c * OnlineMap ) RemoveExpiredIPs (list map [ string ]time. Time ) map [ string ]time. Time {
65+ func (c * OnlineMap ) RemoveExpiredIPs () {
6666 c .access .Lock ()
6767 defer c .access .Unlock ()
6868
6969 now := time .Now ()
70- for k , t := range list {
70+ for k , t := range c . ipList {
7171 diff := now .Sub (t )
7272 if diff .Seconds () > 20 {
73- delete (list , k )
73+ delete (c . ipList , k )
7474 }
7575 }
76- return list
7776}
7877
7978func (c * OnlineMap ) IpTimeMap () map [string ]time.Time {
8079 if time .Since (c .lastCleanup ) > c .cleanupPeriod {
81- c .RemoveExpiredIPs (c . ipList )
80+ c .RemoveExpiredIPs ()
8281 c .lastCleanup = time .Now ()
8382 }
8483
You can’t perform that action at this time.
0 commit comments