fea: add statics for output

This commit is contained in:
Daniel Ding
2024-01-08 20:56:21 +08:00
parent 53dcac37f9
commit c542a184cc
20 changed files with 268 additions and 63 deletions

47
pkg/cache/output.go vendored Executable file
View File

@@ -0,0 +1,47 @@
package cache
import (
"github.com/luscis/openlan/pkg/libol"
"github.com/luscis/openlan/pkg/models"
)
type output struct {
outputs *libol.SafeStrMap
}
func (p *output) Init(size int) {
p.outputs = libol.NewSafeStrMap(size)
}
func (p *output) Add(uuid string, output *models.Output) {
_ = p.outputs.Set(uuid, output)
}
func (p *output) Get(key string) *models.Output {
ret := p.outputs.Get(key)
if ret != nil {
return ret.(*models.Output)
}
return nil
}
func (p *output) Del(key string) {
p.outputs.Del(key)
}
func (p *output) List() <-chan *models.Output {
c := make(chan *models.Output, 128)
go func() {
p.outputs.Iter(func(k string, v interface{}) {
m := v.(*models.Output)
m.Update()
c <- m
})
c <- nil //Finish channel by nil.
}()
return c
}
var Output = output{
outputs: libol.NewSafeStrMap(1024),
}