1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-06-18 22:17:44 +02:00

Add Network.Services handler

This commit is contained in:
Asim Aslam
2019-09-30 07:51:13 +01:00
parent 1322fb0d9d
commit b90871c241
4 changed files with 200 additions and 29 deletions

View File

@ -123,3 +123,23 @@ func (n *Network) Routes(ctx context.Context, req *pbNet.RoutesRequest, resp *pb
return nil
}
// Services returns a list of services based on the routing table
func (n *Network) Services(ctx context.Context, req *pbNet.ServicesRequest, resp *pbNet.ServicesResponse) error {
routes, err := n.Network.Options().Router.Table().List()
if err != nil {
return errors.InternalServerError("go.micro.network", "failed to list services: %s", err)
}
services := make(map[string]bool)
for _, route := range routes {
if _, ok := services[route.Service]; ok {
continue
}
services[route.Service] = true
resp.Services = append(resp.Services, route.Service)
}
return nil
}