xuanbo / eureka-client

eureka client by golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

根据服务名获取服务实例列表

chengjianxi opened this issue · comments

commented

添加一个需求,根据服务名获取注册的服务列表

func (c *Client) GetApplicationInstance(name string) []Instance {
	instances := make([]Instance, 0)
	c.mutex.Lock()
	if c.Applications != nil {
		for _, app := range c.Applications.Applications {
			if app.Name == name {
				instances = append(instances, app.Instances...)
			}
		}
	}
	c.mutex.Unlock()

	return instances
}
commented

虽然现在可以用client.Applications获取所有实例,但是没有锁我觉得不太安全

你可以提交一个PR,我合并进来

commented

别忘了发布个版本