Add 添加IP
(ipType string, scope firewallconfigs.FirewallScope, serverId int64, ip string, expiresAt int64)
| 86 | |
| 87 | // Add 添加IP |
| 88 | func (this *IPList) Add(ipType string, scope firewallconfigs.FirewallScope, serverId int64, ip string, expiresAt int64) { |
| 89 | switch scope { |
| 90 | case firewallconfigs.FirewallScopeGlobal: |
| 91 | ip = "*@" + ip + "@" + ipType |
| 92 | case firewallconfigs.FirewallScopeServer: |
| 93 | ip = types.String(serverId) + "@" + ip + "@" + ipType |
| 94 | default: |
| 95 | ip = "*@" + ip + "@" + ipType |
| 96 | } |
| 97 | |
| 98 | var id = this.nextId() |
| 99 | this.expireList.Add(id, expiresAt) |
| 100 | this.locker.Lock() |
| 101 | |
| 102 | // 删除以前 |
| 103 | oldId, ok := this.ipMap[ip] |
| 104 | if ok { |
| 105 | delete(this.idMap, oldId) |
| 106 | this.expireList.Remove(oldId) |
| 107 | } |
| 108 | |
| 109 | this.ipMap[ip] = id |
| 110 | this.idMap[id] = ip |
| 111 | this.locker.Unlock() |
| 112 | } |
| 113 | |
| 114 | // RecordIP 记录IP |
| 115 | func (this *IPList) RecordIP(ipType string, |