mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-23 05:02:49 +08:00

* breaking upgrade base build image to net5.0 * add make and build tools to image * fix code broken after net5.0 upgrade * fix warnings * fix tests and line endings * upgrade dotnet test and coverages packages * update circle build image * removed rafty and updated more packages * bring back develop * rename authorisation to authorization
36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
namespace Ocelot.Provider.Eureka
|
|
{
|
|
using Ocelot.ServiceDiscovery.Providers;
|
|
using Steeltoe.Discovery;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Ocelot.Values;
|
|
|
|
public class Eureka : IServiceDiscoveryProvider
|
|
{
|
|
private readonly IDiscoveryClient _client;
|
|
private readonly string _serviceName;
|
|
|
|
public Eureka(string serviceName, IDiscoveryClient client)
|
|
{
|
|
_client = client;
|
|
_serviceName = serviceName;
|
|
}
|
|
|
|
public Task<List<Service>> Get()
|
|
{
|
|
var services = new List<Service>();
|
|
|
|
var instances = _client.GetInstances(_serviceName);
|
|
|
|
if (instances != null && instances.Any())
|
|
{
|
|
services.AddRange(instances.Select(i => new Service(i.ServiceId, new ServiceHostAndPort(i.Host, i.Port, i.Uri.Scheme), "", "", new List<string>())));
|
|
}
|
|
|
|
return Task.FromResult(services);
|
|
}
|
|
}
|
|
}
|