From 6d915ece110a7b200812bb03e8eeed2df2bdb0e4 Mon Sep 17 00:00:00 2001 From: token <239573049@qq.com> Date: Mon, 29 Jan 2024 00:11:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0IP=E8=AF=B7=E6=B1=82=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BackgroundServices/GatewayBackground.cs | 4 +-- src/Gateway/Entities/RouteEntity.cs | 1 + src/Gateway/Entities/SettingEntity.cs | 26 ------------------- src/Gateway/GlobalUsing.cs | 2 ++ src/Gateway/Helpers/StringHelper.cs | 2 +- src/Gateway/Options/GatewayOptions.cs | 11 ++++++++ src/Gateway/Program.cs | 6 ++--- src/Gateway/appsettings.json | 3 +++ 8 files changed, 23 insertions(+), 32 deletions(-) delete mode 100644 src/Gateway/Entities/SettingEntity.cs create mode 100644 src/Gateway/Options/GatewayOptions.cs diff --git a/src/Gateway/BackgroundServices/GatewayBackground.cs b/src/Gateway/BackgroundServices/GatewayBackground.cs index 0f18843..adc450c 100644 --- a/src/Gateway/BackgroundServices/GatewayBackground.cs +++ b/src/Gateway/BackgroundServices/GatewayBackground.cs @@ -8,11 +8,11 @@ public class GatewayBackgroundService( protected override async Task ExecuteAsync(CancellationToken stoppingToken) { // 数据库迁移 - freeSql.CodeFirst.SyncStructure(typeof(RouteEntity), typeof(ClusterEntity), typeof(CertificateEntity), typeof(StaticFileProxyEntity), typeof(SettingEntity)); + freeSql.CodeFirst.SyncStructure(typeof(RouteEntity), typeof(ClusterEntity), typeof(CertificateEntity), + typeof(StaticFileProxyEntity)); // 首次启动时更新配置 await gatewayService.RefreshConfig(); await certificateService.RefreshConfig(); } - } \ No newline at end of file diff --git a/src/Gateway/Entities/RouteEntity.cs b/src/Gateway/Entities/RouteEntity.cs index 48ee391..f7be463 100644 --- a/src/Gateway/Entities/RouteEntity.cs +++ b/src/Gateway/Entities/RouteEntity.cs @@ -48,5 +48,6 @@ public sealed class RouteEntity : Entity /// /// 匹配域名 /// + [Column(MapType = typeof(string), StringLength = -1)] public string[] Hosts { get; set; } } diff --git a/src/Gateway/Entities/SettingEntity.cs b/src/Gateway/Entities/SettingEntity.cs deleted file mode 100644 index 3387bca..0000000 --- a/src/Gateway/Entities/SettingEntity.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace Gateway.Entities; - -public sealed class SettingEntity : Entity -{ - /// - /// 设置名称 - /// - public string Name { get; set; } = null!; - - /// - /// 显示名称 - /// - public string? DisplayName { get; set; } = null!; - - /// - /// 设置描述 - /// - public string? Description { get; set; } - - /// - /// 默认值 - /// - public string? DefaultValue { get; set; } - - public Dictionary ExtraProperties { get; set; } = new(); -} \ No newline at end of file diff --git a/src/Gateway/GlobalUsing.cs b/src/Gateway/GlobalUsing.cs index 69f2c6b..3c7e9bf 100644 --- a/src/Gateway/GlobalUsing.cs +++ b/src/Gateway/GlobalUsing.cs @@ -26,3 +26,5 @@ global using Microsoft.IdentityModel.Tokens; global using System.Collections.Concurrent; global using Microsoft.AspNetCore.Http.Features; global using System.Net.NetworkInformation; +global using Gateway.BackgroundServices; +global using Gateway.Tunnel; \ No newline at end of file diff --git a/src/Gateway/Helpers/StringHelper.cs b/src/Gateway/Helpers/StringHelper.cs index 0718f2e..4a9d616 100644 --- a/src/Gateway/Helpers/StringHelper.cs +++ b/src/Gateway/Helpers/StringHelper.cs @@ -13,7 +13,7 @@ public static class StringHelper string[] units = ["B", "KB", "MB", "GB", "TB", "PB", "EB"]; double formattedSize = bytes; - int unitIndex = 0; + var unitIndex = 0; while (formattedSize >= scale && unitIndex < units.Length - 1) { diff --git a/src/Gateway/Options/GatewayOptions.cs b/src/Gateway/Options/GatewayOptions.cs new file mode 100644 index 0000000..7283b95 --- /dev/null +++ b/src/Gateway/Options/GatewayOptions.cs @@ -0,0 +1,11 @@ +namespace Gateway.Options; + +public class GatewayOptions +{ + public const string Name = "Gateway"; + + /// + /// Gateway版本 + /// + public static string? Version { get; set; } +} \ No newline at end of file diff --git a/src/Gateway/Program.cs b/src/Gateway/Program.cs index 462e717..2b1fd2a 100644 --- a/src/Gateway/Program.cs +++ b/src/Gateway/Program.cs @@ -1,8 +1,5 @@ #region FreeSql类型转换 -using Gateway.BackgroundServices; -using Gateway.Tunnel; - Utils.TypeHandlers.TryAdd(typeof(Dictionary), new StringJsonHandler>()); Utils.TypeHandlers.TryAdd(typeof(List), new StringJsonHandler>()); Utils.TypeHandlers.TryAdd(typeof(string[]), new StringJsonHandler()); @@ -27,6 +24,9 @@ var freeSql = new FreeSqlBuilder() builder.Configuration.GetSection(nameof(JwtOptions)) .Get(); +builder.Configuration.GetSection(GatewayOptions.Name) + .Get(); + // 获取环境变量 var https_password = Environment.GetEnvironmentVariable("HTTPS_PASSWORD") ?? "dd666666"; var https_file = Environment.GetEnvironmentVariable("HTTPS_FILE") ?? "gateway.pfx"; diff --git a/src/Gateway/appsettings.json b/src/Gateway/appsettings.json index 748347c..19ccb0b 100644 --- a/src/Gateway/appsettings.json +++ b/src/Gateway/appsettings.json @@ -13,5 +13,8 @@ "JwtOptions": { "Secret": "Das*ist*ein*tokasdf*Passwort*123@#$%^", "ExpireDay": 30 + }, + "Gateway": { + "Version": "1.0.0" } } \ No newline at end of file