Files
openlan/pkg/cache/output.go
Daniel Ding a2ac57b2fc
Some checks failed
Coverage CI / build (push) Has been cancelled
CodeQL / Analyze (go) (push) Has been cancelled
Ubuntu CI / build (push) Has been cancelled
fix: link convert to output.
2025-12-08 16:54:00 +08:00

50 lines
903 B
Go

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(name string) <-chan *models.Output {
c := make(chan *models.Output, 128)
go func() {
p.outputs.Iter(func(k string, v interface{}) {
m := v.(*models.Output)
if name == "" || m.Network == name {
m.Update()
c <- m
}
})
c <- nil //Finish channel by nil.
}()
return c
}
var Output = output{
outputs: libol.NewSafeStrMap(1024),
}