mirror of
https://github.com/luscis/openlan.git
synced 2025-10-15 21:20:37 +08:00
fea: add statics for output
This commit is contained in:
47
pkg/cache/output.go
vendored
Executable file
47
pkg/cache/output.go
vendored
Executable 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),
|
||||
}
|
Reference in New Issue
Block a user