Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeeLyn committed Apr 19, 2019
2 parents 8e782fd + c7f72ec commit 86fa9c8
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 36 deletions.
9 changes: 1 addition & 8 deletions samples/GenericHostSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Uragano.Abstractions.ConsistentHash;
using Uragano.Consul;
using Uragano.Core;
using Uragano.Logging.Exceptionless;
using Uragano.Remoting.LoadBalancing;
using Uragano.ZooKeeper;

namespace GenericHostSample
{
Expand Down
12 changes: 12 additions & 0 deletions src/Uragano.Abstract/EnvironmentVariableReader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Text.RegularExpressions;

namespace Uragano.Abstractions
{
Expand All @@ -9,6 +10,17 @@ public static T Get<T>(string variable, T defaultValue = default)
var value = Environment.GetEnvironmentVariable(variable);
if (string.IsNullOrWhiteSpace(value))
return defaultValue;

value = value.ReplaceIpPlaceholder();

var matches = Regex.Matches(value, "[{](.*?)[}]");
if (matches.Count > 0)
{
foreach (var match in matches)
{
value = value.Replace(match.ToString(), Environment.GetEnvironmentVariable(match.ToString().TrimStart('{').TrimEnd('}')));
}
}
return (T)Convert.ChangeType(value, typeof(T));
}
}
Expand Down
31 changes: 31 additions & 0 deletions src/Uragano.Abstract/EnvironmentVariables.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace Uragano.Abstractions
{
public class EnvironmentVariables
{
public const string uragano_server_addr = "uragano_server_addr";

public const string uragano_server_port = "uragano_server_port";

public const string uragano_server_weight = "uragano_server_weight";

public const string uragano_service_id = "uragano_service_id";

public const string uragano_service_name = "uragano_service_name";

public const string uragano_consul_addr = "uragano_consul_addr";

public const string uragano_consul_token = "uragano_consul_token";

public const string uragano_consul_dc = "uragano_consul_dc";

public const string uragano_consul_timeout = "uragano_consul_timeout";

public const string uragano_consul_hc_interval = "uragano_consul_hc_interval";

public const string uragano_zk_addr = "uragano_zk_addr";

public const string uragano_zk_session_timeout = "uragano_zk_session_timeout";

public const string uragano_zk_readonly = "uragano_zk_readonly";
}
}
5 changes: 4 additions & 1 deletion src/Uragano.Abstract/IPHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace Uragano.Abstractions
public static class IpHelper
{
private static readonly long IpABegin, IpAEnd, IpBBegin, IpBEnd, IpCBegin, IpCEnd;
private const string LocalIp = "{LOCALIP}";
static IpHelper()
{
IpABegin = ConvertIpToNumber(IPAddress.Parse("192.168.0.0"));
Expand Down Expand Up @@ -45,7 +46,9 @@ private static bool InternalIp(IPAddress iPAddress)

public static string ReplaceIpPlaceholder(this string text)
{
return text.Replace("{LocalIP}", GetLocalInternetIp().ToString());
if (!text.Contains(LocalIp))
return text;
return text.Replace(LocalIp, GetLocalInternetIp().ToString());
}
}
}
2 changes: 1 addition & 1 deletion src/Uragano.Abstract/Uragano.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>7.1</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.1-preview.407</Version>
<Version>0.0.1-preview.408</Version>
<Description>A simple, high performance RPC library.</Description>
<PackageProjectUrl>https://github.com/1100100/Uragano</PackageProjectUrl>
<PackageTags>Uragano,RPC,DotNetty,Microservice,MessagePack,DynamicProxy</PackageTags>
Expand Down
6 changes: 3 additions & 3 deletions src/Uragano.Abstract/UraganoSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public class UraganoSettings
public class ServerSettings
{
public string Address { get; set; } =
EnvironmentVariableReader.Get("uragano-server-addr", IpHelper.GetLocalInternetIp().ToString());
EnvironmentVariableReader.Get(EnvironmentVariables.uragano_server_addr, IpHelper.GetLocalInternetIp().ToString());

public int Port { get; set; } = EnvironmentVariableReader.Get("uragano-server-port", 5730);
public int Port { get; set; } = EnvironmentVariableReader.Get(EnvironmentVariables.uragano_server_port, 5730);

public X509Certificate2 X509Certificate2 { get; set; }

public int? Weight { get; set; } = EnvironmentVariableReader.Get("uragano-server-weight", 0);
public int? Weight { get; set; } = EnvironmentVariableReader.Get(EnvironmentVariables.uragano_server_weight, 0);

public override string ToString()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Uragano.Caching.Memory/Uragano.Caching.Memory.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.1-preview.407</Version>
<Version>0.0.1-preview.408</Version>
<Authors>Owen</Authors>
<Company>Owen</Company>
<Description>A simple, high performance RPC library.</Description>
Expand Down
2 changes: 1 addition & 1 deletion src/Uragano.Caching.Redis/Uragano.Caching.Redis.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.1-preview.407</Version>
<Version>0.0.1-preview.408</Version>
<Authors>Owen</Authors>
<Company>Owen</Company>
<Description>A simple, high performance RPC library.</Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.1-preview.407</Version>
<Version>0.0.1-preview.408</Version>
<Description>A simple, high performance RPC library.</Description>
<PackageProjectUrl>https://github.com/1100100/Uragano</PackageProjectUrl>
<PackageIconUrl>https://github.com/1100100/Uragano/blob/master/icon.png?raw=true</PackageIconUrl>
Expand Down
8 changes: 4 additions & 4 deletions src/Uragano.Consul/ConsulClientConfigure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public class ConsulClientConfigure : ConsulClientConfiguration, IServiceDiscover
{
public ConsulClientConfigure()
{
Address = new Uri(EnvironmentVariableReader.Get("uragano-consul-addr", "http://127.0.0.1:8500"));
Token = EnvironmentVariableReader.Get<string>("uragano-consul-token");
Datacenter = EnvironmentVariableReader.Get("uragano-consul-dc", "dc1");
WaitTime = TimeSpan.FromSeconds(EnvironmentVariableReader.Get("uragano-consul-timeout", 10));
Address = new Uri(EnvironmentVariableReader.Get(EnvironmentVariables.uragano_consul_addr, "http://127.0.0.1:8500"));
Token = EnvironmentVariableReader.Get<string>(EnvironmentVariables.uragano_consul_token);
Datacenter = EnvironmentVariableReader.Get(EnvironmentVariables.uragano_consul_dc, "dc1");
WaitTime = TimeSpan.FromSeconds(EnvironmentVariableReader.Get(EnvironmentVariables.uragano_consul_timeout, 10));
}
}
}
6 changes: 3 additions & 3 deletions src/Uragano.Consul/ConsulRegisterServiceConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace Uragano.Consul
{
public class ConsulRegisterServiceConfiguration : IServiceRegisterConfiguration
{
public string Id { get; set; } = EnvironmentVariableReader.Get<string>("uragano-service-id");
public string Id { get; set; } = EnvironmentVariableReader.Get<string>(EnvironmentVariables.uragano_service_id);

public string Name { get; set; } = EnvironmentVariableReader.Get<string>("uragano-service-name");
public string Name { get; set; } = EnvironmentVariableReader.Get<string>(EnvironmentVariables.uragano_service_name);

public bool EnableTagOverride { get; set; }

Expand All @@ -20,6 +20,6 @@ public class ConsulRegisterServiceConfiguration : IServiceRegisterConfiguration
/// <summary>
/// The default is 10 seconds
/// </summary>
public TimeSpan HealthCheckInterval { get; set; } = TimeSpan.FromSeconds(EnvironmentVariableReader.Get("uragano-consul-hc-interval", 10));
public TimeSpan HealthCheckInterval { get; set; } = TimeSpan.FromSeconds(EnvironmentVariableReader.Get(EnvironmentVariables.uragano_consul_hc_interval, 10));
}
}
2 changes: 1 addition & 1 deletion src/Uragano.Consul/Uragano.Consul.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageTags>Uragano,RPC,DotNetty,Microservice,MessagePack,DynamicProxy</PackageTags>
<PackageProjectUrl>https://github.com/1100100/Uragano</PackageProjectUrl>
<Description>A simple, high performance RPC library.</Description>
<Version>0.0.1-preview.407</Version>
<Version>0.0.1-preview.408</Version>
<PackageLicenseUrl>https://github.com/1100100/Uragano/blob/master/LICENSE</PackageLicenseUrl>
<Authors>Owen</Authors>
<Company>Owen</Company>
Expand Down
2 changes: 1 addition & 1 deletion src/Uragano.Core/Uragano.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<PackageIconUrl>https://github.com/1100100/Uragano/blob/master/icon.png?raw=true</PackageIconUrl>
<PackageProjectUrl>https://github.com/1100100/Uragano</PackageProjectUrl>
<Description>A simple, high performance RPC library.</Description>
<Version>0.0.1-preview.407</Version>
<Version>0.0.1-preview.408</Version>
<PackageLicenseUrl>https://github.com/1100100/Uragano/blob/master/LICENSE</PackageLicenseUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>Owen</Authors>
Expand Down
2 changes: 1 addition & 1 deletion src/Uragano.DynamicProxy/Uragano.DynamicProxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageIconUrl>https://github.com/1100100/Uragano/blob/master/icon.png?raw=true</PackageIconUrl>
<PackageProjectUrl>https://github.com/1100100/Uragano</PackageProjectUrl>
<Description>A simple, high performance RPC library.</Description>
<Version>0.0.1-preview.407</Version>
<Version>0.0.1-preview.408</Version>
<PackageLicenseUrl>https://github.com/1100100/Uragano/blob/master/LICENSE</PackageLicenseUrl>
<Authors>Owen</Authors>
<Company>Owen</Company>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.1-preview.407</Version>
<Version>0.0.1-preview.408</Version>
<Authors>Owen</Authors>
<Company>Owen</Company>
<Description>A simple, high performance RPC library.</Description>
Expand Down
2 changes: 1 addition & 1 deletion src/Uragano.Logging.Log4net/Uragano.Logging.Log4Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.1-preview.407</Version>
<Version>0.0.1-preview.408</Version>
<Authors>Owen</Authors>
<Company>Owen</Company>
<Description>A simple, high performance RPC library.</Description>
Expand Down
2 changes: 1 addition & 1 deletion src/Uragano.Logging.NLog/Uragano.Logging.NLog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<Version>0.0.1-preview.407</Version>
<Version>0.0.1-preview.408</Version>
<Authors>Owen</Authors>
<Company>Owen</Company>
<Description>A simple, high performance RPC library.</Description>
Expand Down
2 changes: 1 addition & 1 deletion src/Uragano.Remoting/Uragano.Remoting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageIconUrl>https://github.com/1100100/Uragano/blob/master/icon.png?raw=true</PackageIconUrl>
<PackageProjectUrl>https://github.com/1100100/Uragano</PackageProjectUrl>
<Description>A simple, high performance RPC library.</Description>
<Version>0.0.1-preview.407</Version>
<Version>0.0.1-preview.408</Version>
<PackageLicenseUrl>https://github.com/1100100/Uragano/blob/master/LICENSE</PackageLicenseUrl>
<Authors>Owen</Authors>
<Company>Owen</Company>
Expand Down
2 changes: 1 addition & 1 deletion src/Uragano.ZooKeeper/Uragano.ZooKeeper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<Version>0.0.1-preview.407</Version>
<Version>0.0.1-preview.408</Version>
<Authors>Owen</Authors>
<Product>Uragano.ZooKeeper</Product>
<Description>A simple, high performance RPC library.</Description>
Expand Down
6 changes: 3 additions & 3 deletions src/Uragano.ZooKeeper/ZooKeeperClientConfigure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public class ZooKeeperClientConfigure : IServiceDiscoveryClientConfiguration
/// comma separated host:port pairs, each corresponding to a zk server.
/// </summary>
public string ConnectionString { get; set; } =
EnvironmentVariableReader.Get("uragano-zk-addr", "localhost:2181");
EnvironmentVariableReader.Get(EnvironmentVariables.uragano_zk_addr, "127.0.0.1:2181");

/// <summary>
/// session timeout in milliseconds
/// </summary>
public int SessionTimeout { get; set; } = EnvironmentVariableReader.Get("uragano-zk-session-timeout", 1000 * 10);
public int SessionTimeout { get; set; } = EnvironmentVariableReader.Get(EnvironmentVariables.uragano_zk_session_timeout, 1000 * 10);


/// <summary>
Expand All @@ -23,6 +23,6 @@ public class ZooKeeperClientConfigure : IServiceDiscoveryClientConfiguration
/// server it could reach, it connects to one in read-only mode, i.e. read requests are allowed while write requests are not.
/// It continues seeking for majority in the background.
/// </summary>
public bool CanBeReadOnly { get; set; } = EnvironmentVariableReader.Get("uragano-zk-readonly", false);
public bool CanBeReadOnly { get; set; } = EnvironmentVariableReader.Get(EnvironmentVariables.uragano_zk_readonly, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace Uragano.ZooKeeper
{
public class ZooKeeperRegisterServiceConfiguration : IServiceRegisterConfiguration
{
public string Id { get; set; } = EnvironmentVariableReader.Get<string>("uragano-service-id");
public string Name { get; set; } = EnvironmentVariableReader.Get<string>("uragano-service-name");
public string Id { get; set; } = EnvironmentVariableReader.Get<string>(EnvironmentVariables.uragano_service_id);
public string Name { get; set; } = EnvironmentVariableReader.Get<string>(EnvironmentVariables.uragano_service_name);

public override string ToString()
{
Expand Down

0 comments on commit 86fa9c8

Please sign in to comment.