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

Method Save

internal/waf/ip_list.go:237–263  ·  view source on GitHub ↗

Save to local file

(path string)

Source from the content-addressed store, hash-verified

235
236// Save to local file
237func (this *IPList) Save(path string) error {
238 var itemMaps = []maps.Map{} // [ {ip info, expiresAt }, ... ]
239 this.locker.Lock()
240 defer this.locker.Unlock()
241
242 // prevent too many items
243 if len(this.ipMap) > 100_000 {
244 return nil
245 }
246
247 for ipInfo, id := range this.ipMap {
248 var expiresAt = this.expireList.ExpiresAt(id)
249 if expiresAt <= 0 {
250 continue
251 }
252 itemMaps = append(itemMaps, maps.Map{
253 "ip": ipInfo,
254 "expiresAt": expiresAt,
255 })
256 }
257
258 itemMapsJSON, err := json.Marshal(itemMaps)
259 if err != nil {
260 return err
261 }
262 return os.WriteFile(path, itemMapsJSON, 0666)
263}
264
265// Load from local file
266func (this *IPList) Load(path string) error {

Callers 1

initFunction · 0.45

Calls 4

WriteFileMethod · 0.80
ExpiresAtMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected