amuz.es/src/infra/goutils@v0.1.3/logger/rotater/set_logcore.go (about) 1 package rotater 2 3 import ( 4 "sync" 5 "sync/atomic" 6 "amuz.es/src/infra/goutils/logger" 7 ) 8 9 /** 10 logger set 11 */ 12 type RotateSyncerSet struct { 13 storage sync.Map 14 } 15 16 func (s *RotateSyncerSet) Delete(key logger.RotateSyncer) { 17 s.storage.Delete(key) 18 } 19 func (s *RotateSyncerSet) Exist(key logger.RotateSyncer) (ok bool) { 20 _, ok = s.storage.Load(key) 21 return 22 } 23 func (s *RotateSyncerSet) SetNx(key logger.RotateSyncer) (bool) { 24 _, exist := s.storage.LoadOrStore(key, 0) 25 return !exist 26 } 27 func (s *RotateSyncerSet) Range(f func(key logger.RotateSyncer)) { 28 s.storage.Range(s.rangeWrap(f)) 29 } 30 func (s *RotateSyncerSet) Store(key logger.RotateSyncer) { 31 s.storage.Store(key, 0) 32 } 33 func (s *RotateSyncerSet) rangeWrap(f func(key logger.RotateSyncer)) func(key, value interface{}) bool { 34 ok := true 35 return func(key, value interface{}) bool { 36 f(key.(logger.RotateSyncer)) 37 return ok 38 } 39 } 40 41 func (s *RotateSyncerSet) Len() int { 42 var count uint64 43 s.Range(func(conn logger.RotateSyncer) { 44 atomic.AddUint64(&count, 1) 45 }) 46 return int(count) 47 }