mirror of
https://github.com/Icinga/icingadb.git
synced 2026-05-28 04:35:54 -04:00
Introduce EntitiesById
This commit is contained in:
parent
d36928afd3
commit
3974a7bd4f
1 changed files with 44 additions and 0 deletions
44
pkg/icingadb/entitiesbyid.go
Normal file
44
pkg/icingadb/entitiesbyid.go
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
package icingadb
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/icinga/icingadb/pkg/contracts"
|
||||
)
|
||||
|
||||
type EntitiesById map[string]contracts.Entity
|
||||
|
||||
func (ebi EntitiesById) Keys() []string {
|
||||
keys := make([]string, 0, len(ebi))
|
||||
for k := range ebi {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
|
||||
return keys
|
||||
}
|
||||
|
||||
func (ebi EntitiesById) IDs() []interface{} {
|
||||
ids := make([]interface{}, 0, len(ebi))
|
||||
for _, v := range ebi {
|
||||
ids = append(ids, v.(contracts.IDer).ID())
|
||||
}
|
||||
|
||||
return ids
|
||||
}
|
||||
|
||||
func (ebi EntitiesById) Entities(ctx context.Context) <-chan contracts.Entity {
|
||||
entities := make(chan contracts.Entity, 0)
|
||||
|
||||
go func() {
|
||||
defer close(entities)
|
||||
|
||||
for _, v := range ebi {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case entities <- v:
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return entities
|
||||
}
|
||||
Loading…
Reference in a new issue