mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 22:08:17 +08:00
Add ability to specify scheme of ServiceProviderConfiguration
This commit is contained in:
@ -9,7 +9,7 @@
|
||||
{
|
||||
return new ConsulClient(c =>
|
||||
{
|
||||
c.Address = new Uri($"http://{config.Host}:{config.Port}");
|
||||
c.Address = new Uri($"{config.Scheme}://{config.Host}:{config.Port}");
|
||||
|
||||
if (!string.IsNullOrEmpty(config?.Token))
|
||||
{
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
var consulFactory = provider.GetService<IConsulClientFactory>();
|
||||
|
||||
var consulRegistryConfiguration = new ConsulRegistryConfiguration(config.Host, config.Port, reRoute.ServiceName, config.Token);
|
||||
var consulRegistryConfiguration = new ConsulRegistryConfiguration(config.Scheme, config.Host, config.Port, reRoute.ServiceName, config.Token);
|
||||
|
||||
var consulServiceDiscoveryProvider = new Consul(consulRegistryConfiguration, factory, consulFactory);
|
||||
|
||||
|
@ -2,15 +2,17 @@
|
||||
{
|
||||
public class ConsulRegistryConfiguration
|
||||
{
|
||||
public ConsulRegistryConfiguration(string host, int port, string keyOfServiceInConsul, string token)
|
||||
public ConsulRegistryConfiguration(string scheme, string host, int port, string keyOfServiceInConsul, string token)
|
||||
{
|
||||
Host = string.IsNullOrEmpty(host) ? "localhost" : host;
|
||||
Port = port > 0 ? port : 8500;
|
||||
Scheme = string.IsNullOrEmpty(scheme) ? "http" : scheme;
|
||||
KeyOfServiceInConsul = keyOfServiceInConsul;
|
||||
Token = token;
|
||||
}
|
||||
|
||||
public string KeyOfServiceInConsul { get; }
|
||||
public string Scheme { get; }
|
||||
public string Host { get; }
|
||||
public int Port { get; }
|
||||
public string Token { get; }
|
||||
|
@ -2,6 +2,7 @@ namespace Ocelot.Configuration.Builder
|
||||
{
|
||||
public class ServiceProviderConfigurationBuilder
|
||||
{
|
||||
private string _serviceDiscoveryProviderScheme;
|
||||
private string _serviceDiscoveryProviderHost;
|
||||
private int _serviceDiscoveryProviderPort;
|
||||
private string _type;
|
||||
@ -10,6 +11,12 @@ namespace Ocelot.Configuration.Builder
|
||||
private int _pollingInterval;
|
||||
private string _namespace;
|
||||
|
||||
public ServiceProviderConfigurationBuilder WithScheme(string serviceDiscoveryProviderScheme)
|
||||
{
|
||||
_serviceDiscoveryProviderScheme = serviceDiscoveryProviderScheme;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ServiceProviderConfigurationBuilder WithHost(string serviceDiscoveryProviderHost)
|
||||
{
|
||||
_serviceDiscoveryProviderHost = serviceDiscoveryProviderHost;
|
||||
@ -54,7 +61,7 @@ namespace Ocelot.Configuration.Builder
|
||||
|
||||
public ServiceProviderConfiguration Build()
|
||||
{
|
||||
return new ServiceProviderConfiguration(_type, _serviceDiscoveryProviderHost, _serviceDiscoveryProviderPort, _token, _configurationKey, _pollingInterval, _namespace);
|
||||
return new ServiceProviderConfiguration(_type, _serviceDiscoveryProviderScheme, _serviceDiscoveryProviderHost, _serviceDiscoveryProviderPort, _token, _configurationKey, _pollingInterval, _namespace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ namespace Ocelot.Configuration.Creator
|
||||
public ServiceProviderConfiguration Create(FileGlobalConfiguration globalConfiguration)
|
||||
{
|
||||
var port = globalConfiguration?.ServiceDiscoveryProvider?.Port ?? 0;
|
||||
var scheme = globalConfiguration?.ServiceDiscoveryProvider?.Scheme ?? "http";
|
||||
var host = globalConfiguration?.ServiceDiscoveryProvider?.Host ?? "localhost";
|
||||
var type = !string.IsNullOrEmpty(globalConfiguration?.ServiceDiscoveryProvider?.Type)
|
||||
? globalConfiguration?.ServiceDiscoveryProvider?.Type
|
||||
@ -16,6 +17,7 @@ namespace Ocelot.Configuration.Creator
|
||||
var k8snamespace = globalConfiguration?.ServiceDiscoveryProvider?.Namespace ?? string.Empty;
|
||||
|
||||
return new ServiceProviderConfigurationBuilder()
|
||||
.WithScheme(scheme)
|
||||
.WithHost(host)
|
||||
.WithPort(port)
|
||||
.WithType(type)
|
||||
|
@ -2,6 +2,7 @@ namespace Ocelot.Configuration.File
|
||||
{
|
||||
public class FileServiceDiscoveryProvider
|
||||
{
|
||||
public string Scheme { get; set; }
|
||||
public string Host { get; set; }
|
||||
public int Port { get; set; }
|
||||
public string Type { get; set; }
|
||||
|
@ -2,9 +2,10 @@
|
||||
{
|
||||
public class ServiceProviderConfiguration
|
||||
{
|
||||
public ServiceProviderConfiguration(string type, string host, int port, string token, string configurationKey, int pollingInterval, string @namespace = "")
|
||||
public ServiceProviderConfiguration(string type, string scheme, string host, int port, string token, string configurationKey, int pollingInterval, string @namespace = "")
|
||||
{
|
||||
ConfigurationKey = configurationKey;
|
||||
Scheme = scheme;
|
||||
Host = host;
|
||||
Port = port;
|
||||
Token = token;
|
||||
@ -13,6 +14,8 @@
|
||||
Namespace = @namespace;
|
||||
}
|
||||
|
||||
public string Scheme { get; }
|
||||
|
||||
public string Host { get; }
|
||||
|
||||
public int Port { get; }
|
||||
|
Reference in New Issue
Block a user