mirror of
https://github.com/FastTunnel/FastTunnel.git
synced 2025-02-08 02:39:29 +08:00
add configbuilder
This commit is contained in:
parent
8691c01078
commit
b7705878fa
|
@ -4,16 +4,16 @@ using System.Text;
|
|||
|
||||
namespace FastTunnel.Core.Config
|
||||
{
|
||||
public class ServerConfig
|
||||
public class DefaultServerConfig : IServerConfig
|
||||
{
|
||||
public string BindAddr { get; set; }
|
||||
|
||||
public int BindPort { get; set; }
|
||||
|
||||
public int ProxyPort_HTTP { get; set; }
|
||||
public int ProxyPort_HTTP { get; set; } = 1270;
|
||||
|
||||
public string Domain { get; set; }
|
||||
|
||||
public bool HasNginxProxy { get; set; }
|
||||
public bool HasNginxProxy { get; set; } = false;
|
||||
}
|
||||
}
|
50
FastTunnel.Core/Config/DefaultServerConfigBuilder.cs
Normal file
50
FastTunnel.Core/Config/DefaultServerConfigBuilder.cs
Normal file
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace FastTunnel.Core.Config
|
||||
{
|
||||
public class DefaultServerConfigBuilder
|
||||
{
|
||||
readonly DefaultServerConfig _options = new DefaultServerConfig();
|
||||
|
||||
public DefaultServerConfigBuilder WithBindInfo(string host, int port)
|
||||
{
|
||||
_options.BindAddr = host;
|
||||
_options.BindPort = port;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DefaultServerConfigBuilder WithWebDomain(string domain)
|
||||
{
|
||||
_options.Domain = domain;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DefaultServerConfigBuilder WithHasNginxProxy(bool has)
|
||||
{
|
||||
_options.HasNginxProxy = has;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DefaultServerConfigBuilder WithHTTPPort(int port)
|
||||
{
|
||||
_options.ProxyPort_HTTP = port;
|
||||
return this;
|
||||
}
|
||||
|
||||
public DefaultServerConfig Build()
|
||||
{
|
||||
if (string.IsNullOrEmpty(_options.BindAddr))
|
||||
throw new ArgumentNullException("You must use WithBindInfo to set host");
|
||||
|
||||
if (_options.BindPort == 0)
|
||||
throw new ArgumentNullException("You must use WithBindInfo to set port");
|
||||
|
||||
if (string.IsNullOrEmpty(_options.Domain))
|
||||
throw new ArgumentNullException("You must use WithWebDomain to set domain");
|
||||
|
||||
return _options;
|
||||
}
|
||||
}
|
||||
}
|
19
FastTunnel.Core/Config/IServerConfig.cs
Normal file
19
FastTunnel.Core/Config/IServerConfig.cs
Normal file
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace FastTunnel.Core.Config
|
||||
{
|
||||
public interface IServerConfig
|
||||
{
|
||||
string BindAddr { get; set; }
|
||||
|
||||
int BindPort { get; set; }
|
||||
|
||||
int ProxyPort_HTTP { get; set; }
|
||||
|
||||
string Domain { get; set; }
|
||||
|
||||
bool HasNginxProxy { get; set; }
|
||||
}
|
||||
}
|
|
@ -25,7 +25,8 @@ namespace FastTunnel.Core.Core
|
|||
public Dictionary<string, NewRequest> newRequest = new Dictionary<string, NewRequest>();
|
||||
public Dictionary<string, WebInfo> WebList = new Dictionary<string, WebInfo>();
|
||||
public Dictionary<int, SSHInfo<SSHHandlerArg>> SSHList = new Dictionary<int, SSHInfo<SSHHandlerArg>>();
|
||||
public ServerConfig _serverSettings;
|
||||
|
||||
public IServerConfig _serverSettings { get; set; }
|
||||
|
||||
ILogger<FastTunnelServer> _logger;
|
||||
|
||||
|
@ -41,7 +42,7 @@ namespace FastTunnel.Core.Core
|
|||
_swapMsgHandler = swapMsgHandler;
|
||||
}
|
||||
|
||||
public void Run(ServerConfig settings)
|
||||
public void Run(IServerConfig settings)
|
||||
{
|
||||
_serverSettings = settings;
|
||||
_logger.LogDebug("FastTunnel Server Start");
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
<RepositoryType>git</RepositoryType>
|
||||
<PackageTags>FastTunnel.Core</PackageTags>
|
||||
<PackageReleaseNotes>FastTunnel.Core</PackageReleaseNotes>
|
||||
<Version>1.0.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -8,6 +8,6 @@ namespace FastTunnel.Server
|
|||
{
|
||||
public class Appsettings
|
||||
{
|
||||
public ServerConfig ServerSettings { get; set; }
|
||||
public DefaultServerConfig ServerSettings { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using FastTunnel.Core.Core;
|
||||
using FastTunnel.Core.Config;
|
||||
using FastTunnel.Core.Core;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
@ -29,7 +30,14 @@ namespace FastTunnel.Server.Service
|
|||
|
||||
try
|
||||
{
|
||||
Run();
|
||||
var setting = _configuration.Get<Appsettings>().ServerSettings;
|
||||
|
||||
_fastTunnelServer.Run(
|
||||
new DefaultServerConfigBuilder()
|
||||
.WithBindInfo(setting.BindAddr, setting.BindPort)
|
||||
.WithHasNginxProxy(setting.HasNginxProxy)
|
||||
.WithWebDomain(setting.Domain)
|
||||
.WithHTTPPort(setting.ProxyPort_HTTP).Build());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -41,11 +49,6 @@ namespace FastTunnel.Server.Service
|
|||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void Run()
|
||||
{
|
||||
_fastTunnelServer.Run(_configuration.Get<Appsettings>().ServerSettings);
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_logger.LogInformation("===== FastTunnel Server Stoping =====");
|
||||
|
|
Loading…
Reference in New Issue
Block a user