vanity/router/cache.go

33 lines
519 B
Go
Raw Normal View History

package router
import (
"sync"
"go.jolheiser.com/vanity/service"
)
var cache = &packageCache{
packages: make(map[string]*service.Package),
}
type packageCache struct {
packages map[string]*service.Package
sync.Mutex
}
func (c *packageCache) Update(packages map[string]*service.Package) {
c.Lock()
c.packages = packages
c.Unlock()
}
func (c *packageCache) Names() []string {
names := make([]string, len(c.packages))
idx := 0
for name := range c.packages {
names[idx] = name
idx++
}
return names
}