From 09957364e2755a9dc644828f7583ce322223f78a Mon Sep 17 00:00:00 2001 From: movingsam Date: Sun, 1 Mar 2026 17:00:48 +0800 Subject: [PATCH] =?UTF-8?q?feat(plugin):=20=E6=B7=BB=E5=8A=A0=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=8A=BD=E8=B1=A1=E5=B1=82=E9=A1=B9=E7=9B=AE=20Fengli?= =?UTF-8?q?ng.Gateway.Plugin.Abstractions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 创建插件接口定义 (IGatewayPlugin, IRequestPlugin, IResponsePlugin, IRouteTransformPlugin, ILoadBalancePlugin) - 添加 YARP 引用用于类型定义 --- YarpGateway.slnx | 3 + src/Directory.Packages.props | 4 ++ ...engling.Gateway.Plugin.Abstractions.csproj | 14 +++++ .../IGatewayPlugin.cs | 63 +++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 src/Fengling.Gateway.Plugin.Abstractions/Fengling.Gateway.Plugin.Abstractions.csproj create mode 100644 src/Fengling.Gateway.Plugin.Abstractions/IGatewayPlugin.cs diff --git a/YarpGateway.slnx b/YarpGateway.slnx index 586dfed..f391d42 100644 --- a/YarpGateway.slnx +++ b/YarpGateway.slnx @@ -5,6 +5,9 @@ + + + diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index be76ff7..5d69c13 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -12,6 +12,10 @@ + + + + diff --git a/src/Fengling.Gateway.Plugin.Abstractions/Fengling.Gateway.Plugin.Abstractions.csproj b/src/Fengling.Gateway.Plugin.Abstractions/Fengling.Gateway.Plugin.Abstractions.csproj new file mode 100644 index 0000000..0c5abb0 --- /dev/null +++ b/src/Fengling.Gateway.Plugin.Abstractions/Fengling.Gateway.Plugin.Abstractions.csproj @@ -0,0 +1,14 @@ + + + + net10.0 + enable + enable + Fengling.Gateway.Plugin.Abstractions + + + + + + + diff --git a/src/Fengling.Gateway.Plugin.Abstractions/IGatewayPlugin.cs b/src/Fengling.Gateway.Plugin.Abstractions/IGatewayPlugin.cs new file mode 100644 index 0000000..ffa436e --- /dev/null +++ b/src/Fengling.Gateway.Plugin.Abstractions/IGatewayPlugin.cs @@ -0,0 +1,63 @@ +using Microsoft.AspNetCore.Http; +using Yarp.ReverseProxy.Configuration; +using Yarp.ReverseProxy.Model; + +namespace Fengling.Gateway.Plugin.Abstractions; + +/// +/// 插件基础接口 +/// +public interface IGatewayPlugin +{ + string Name { get; } + string Version { get; } + string? Description { get; } + + Task OnLoadAsync(); + Task OnUnloadAsync(); +} + +/// +/// 请求处理插件 +/// +public interface IRequestPlugin : IGatewayPlugin +{ + /// 请求到达网关前 + Task OnRequestAsync(HttpContext context); + + /// 路由决策后 + Task OnRouteMatchedAsync(HttpContext context, RouteConfig route); + + /// 转发到后端前 + Task OnForwardingAsync(HttpContext context, HttpRequestMessage request); +} + +/// +/// 响应处理插件 +/// +public interface IResponsePlugin : IGatewayPlugin +{ + /// 后端响应后 + Task OnBackendResponseAsync(HttpContext context, HttpResponseMessage response); + + /// 返回客户端前 + Task OnResponseFinalizingAsync(HttpContext context); +} + +/// +/// 路由转换插件 +/// +public interface IRouteTransformPlugin : IGatewayPlugin +{ + Task TransformRouteAsync(RouteConfig original, HttpContext context); +} + +/// +/// 负载均衡插件 +/// +public interface ILoadBalancePlugin : IGatewayPlugin +{ + Task SelectDestinationAsync( + IReadOnlyList destinations, + HttpContext context); +}