add store remove

This commit is contained in:
lyyyuna 2020-09-16 17:16:57 +08:00
parent 06a4e4a61b
commit a22229cd1b

View File

@ -45,6 +45,9 @@ type Store interface {
// Set stores the services information into internal state
Set(services map[string][]string)
// Remove the service from the store
Remove(s Service) error
}
// fileStore holds the registered services into memory and persistent to a local file
@ -245,3 +248,19 @@ func (l *memoryStore) Set(services map[string][]string) {
l.servicesMap = services
}
func (l *memoryStore) Remove(s Service) error {
l.mu.Lock()
defer l.mu.Unlock()
services := l.servicesMap[s.Name]
newServices := make([]string, 0)
for _, addr := range services {
if addr != s.Address {
newServices = append(newServices, addr)
}
}
l.servicesMap[s.Name] = newServices
return nil
}