MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Load

Method Load

internal/waf/ip_list.go:266–299  ·  view source on GitHub ↗

Load from local file

(path string)

Source from the content-addressed store, hash-verified

264
265// Load from local file
266func (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
302func (this *IPList) IPMap() map[string]uint64 {

Callers 2

TestIPList_SaveFunction · 0.45
initFunction · 0.45

Calls 6

nextIdMethod · 0.95
NowFunction · 0.92
UnixMethod · 0.80
AddMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by 1

TestIPList_SaveFunction · 0.36