var.go 715 B

1234567891011121314151617181920212223242526272829303132333435
  1. package g
  2. import (
  3. "sync"
  4. "github.com/710leo/urlooker/dataobj"
  5. )
  6. type DetectedItemSafeMap struct {
  7. sync.RWMutex
  8. M map[string][]*dataobj.DetectedItem
  9. }
  10. var (
  11. DetectedItemMap = &DetectedItemSafeMap{M: make(map[string][]*dataobj.DetectedItem)}
  12. )
  13. func (this *DetectedItemSafeMap) Get(key string) ([]*dataobj.DetectedItem, bool) {
  14. this.RLock()
  15. defer this.RUnlock()
  16. ipItem, exists := this.M[key]
  17. return ipItem, exists
  18. }
  19. func (this *DetectedItemSafeMap) GetAll() map[string][]*dataobj.DetectedItem {
  20. this.RLock()
  21. defer this.RUnlock()
  22. return this.M
  23. }
  24. func (this *DetectedItemSafeMap) Set(detectedItemMap map[string][]*dataobj.DetectedItem) {
  25. this.Lock()
  26. defer this.Unlock()
  27. this.M = detectedItemMap
  28. }