Merge pull request #815 from micro/broker

Add broker service implementation
This commit is contained in:
Asim Aslam
2019-10-04 17:23:29 +01:00
committed by GitHub
9 changed files with 885 additions and 16 deletions

View File

@@ -100,7 +100,7 @@ func (c *cache) quit() bool {
func (c *cache) del(service string) {
// don't blow away cache in error state
if err := c.getStatus(); err != nil {
if err := c.status; err != nil {
return
}
// otherwise delete entries
@@ -116,14 +116,13 @@ func (c *cache) get(service string) ([]*registry.Service, error) {
services := c.cache[service]
// get cache ttl
ttl := c.ttls[service]
// make a copy
cp := registry.Copy(services)
// got services && within ttl so return cache
if c.isValid(services, ttl) {
// make a copy
cp := registry.Copy(services)
// unlock the read
if c.isValid(cp, ttl) {
c.RUnlock()
// return servics
// return services
return cp, nil
}
@@ -136,8 +135,9 @@ func (c *cache) get(service string) ([]*registry.Service, error) {
if len(cached) > 0 {
// set the error status
c.setStatus(err)
// return the stale cache
return registry.Copy(cached), nil
return cached, nil
}
// otherwise return error
return nil, err
@@ -165,7 +165,7 @@ func (c *cache) get(service string) ([]*registry.Service, error) {
c.RUnlock()
// get and return services
return get(service, services)
return get(service, cp)
}
func (c *cache) set(service string, services []*registry.Service) {