Load from local file
(path string)
| 264 | |
| 265 | // Load from local file |
| 266 | func (this *IPList) Load(path string) error { |
| 267 | data, err := os.ReadFile(path) |
| 268 | if err != nil { |
| 269 | return err |
| 270 | } |
| 271 | if len(data) == 0 { |
| 272 | return nil |
| 273 | } |
| 274 | |
| 275 | var itemMaps = []maps.Map{} |
| 276 | err = json.Unmarshal(data, &itemMaps) |
| 277 | if err != nil { |
| 278 | return err |
| 279 | } |
| 280 | |
| 281 | this.locker.Lock() |
| 282 | defer this.locker.Unlock() |
| 283 | |
| 284 | for _, itemMap := range itemMaps { |
| 285 | var ip = itemMap.GetString("ip") |
| 286 | var expiresAt = itemMap.GetInt64("expiresAt") |
| 287 | if len(ip) == 0 || expiresAt < fasttime.Now().Unix()+10 /** seconds **/ { |
| 288 | continue |
| 289 | } |
| 290 | |
| 291 | var id = this.nextId() |
| 292 | this.expireList.Add(id, expiresAt) |
| 293 | |
| 294 | this.ipMap[ip] = id |
| 295 | this.idMap[id] = ip |
| 296 | } |
| 297 | |
| 298 | return nil |
| 299 | } |
| 300 | |
| 301 | // IPMap get ipMap |
| 302 | func (this *IPList) IPMap() map[string]uint64 { |