diff --git a/producer/proto/producer_nf.go b/producer/proto/producer_nf.go index 2a622503..d57925cc 100644 --- a/producer/proto/producer_nf.go +++ b/producer/proto/producer_nf.go @@ -18,16 +18,19 @@ type SamplingRateSystem interface { AddSamplingRate(version uint16, obsDomainId uint32, samplingRate uint32) } +type basicSamplingRateKey struct { + version uint16 + obsDomainId uint32 +} + type basicSamplingRateSystem struct { - //sampling map[uint16]map[uint32]uint32 - sampling map[string]uint32 + sampling map[basicSamplingRateKey]uint32 samplinglock *sync.RWMutex } func CreateSamplingSystem() SamplingRateSystem { ts := &basicSamplingRateSystem{ - //sampling: make(map[uint16]map[uint32]uint32), - sampling: make(map[string]uint32), + sampling: make(map[basicSamplingRateKey]uint32), samplinglock: &sync.RWMutex{}, } return ts @@ -36,18 +39,19 @@ func CreateSamplingSystem() SamplingRateSystem { func (s *basicSamplingRateSystem) AddSamplingRate(version uint16, obsDomainId uint32, samplingRate uint32) { s.samplinglock.Lock() defer s.samplinglock.Unlock() - /*_, exists := s.sampling[version] - if exists != true { - s.sampling[version] = make(map[uint32]uint32) - } - s.sampling[version][obsDomainId] = samplingRate*/ - s.sampling[fmt.Sprintf("%d-%d", version, obsDomainId)] = samplingRate + s.sampling[basicSamplingRateKey{ + version: version, + obsDomainId: obsDomainId, + }] = samplingRate } func (s *basicSamplingRateSystem) GetSamplingRate(version uint16, obsDomainId uint32) (uint32, error) { s.samplinglock.RLock() defer s.samplinglock.RUnlock() - if samplingRate, ok := s.sampling[fmt.Sprintf("%d-%d", version, obsDomainId)]; ok { + if samplingRate, ok := s.sampling[basicSamplingRateKey{ + version: version, + obsDomainId: obsDomainId, + }]; ok { return samplingRate, nil }