feat(plugin): 添加插件抽象层项目 Fengling.Gateway.Plugin.Abstractions
- 创建插件接口定义 (IGatewayPlugin, IRequestPlugin, IResponsePlugin, IRouteTransformPlugin, ILoadBalancePlugin) - 添加 YARP 引用用于类型定义
This commit is contained in:
parent
a96ba1f3d2
commit
09957364e2
@ -5,6 +5,9 @@
|
||||
</Folder>
|
||||
<Folder Name="/src/">
|
||||
<Project Path="src/YarpGateway.csproj" />
|
||||
<Project Path="src/Fengling.Gateway.Plugin.Abstractions/Fengling.Gateway.Plugin.Abstractions.csproj" />
|
||||
</Folder>
|
||||
<Project Path="src/YarpGateway.csproj" />
|
||||
</Folder>
|
||||
<Folder Name="/tests/">
|
||||
<Project Path="tests/YarpGateway.Tests/YarpGateway.Tests.csproj" />
|
||||
|
||||
@ -12,6 +12,10 @@
|
||||
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.2" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.2" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="10.0.2" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.2" />
|
||||
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="10.0.0" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.2" />
|
||||
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="10.0.2" />
|
||||
|
||||
<!-- Database -->
|
||||
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.0" />
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>Fengling.Gateway.Plugin.Abstractions</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Yarp.ReverseProxy" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
63
src/Fengling.Gateway.Plugin.Abstractions/IGatewayPlugin.cs
Normal file
63
src/Fengling.Gateway.Plugin.Abstractions/IGatewayPlugin.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Yarp.ReverseProxy.Configuration;
|
||||
using Yarp.ReverseProxy.Model;
|
||||
|
||||
namespace Fengling.Gateway.Plugin.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// 插件基础接口
|
||||
/// </summary>
|
||||
public interface IGatewayPlugin
|
||||
{
|
||||
string Name { get; }
|
||||
string Version { get; }
|
||||
string? Description { get; }
|
||||
|
||||
Task OnLoadAsync();
|
||||
Task OnUnloadAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求处理插件
|
||||
/// </summary>
|
||||
public interface IRequestPlugin : IGatewayPlugin
|
||||
{
|
||||
/// <summary>请求到达网关前</summary>
|
||||
Task<HttpContext?> OnRequestAsync(HttpContext context);
|
||||
|
||||
/// <summary>路由决策后</summary>
|
||||
Task<HttpContext?> OnRouteMatchedAsync(HttpContext context, RouteConfig route);
|
||||
|
||||
/// <summary>转发到后端前</summary>
|
||||
Task<HttpContext?> OnForwardingAsync(HttpContext context, HttpRequestMessage request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 响应处理插件
|
||||
/// </summary>
|
||||
public interface IResponsePlugin : IGatewayPlugin
|
||||
{
|
||||
/// <summary>后端响应后</summary>
|
||||
Task OnBackendResponseAsync(HttpContext context, HttpResponseMessage response);
|
||||
|
||||
/// <summary>返回客户端前</summary>
|
||||
Task OnResponseFinalizingAsync(HttpContext context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 路由转换插件
|
||||
/// </summary>
|
||||
public interface IRouteTransformPlugin : IGatewayPlugin
|
||||
{
|
||||
Task<RouteConfig> TransformRouteAsync(RouteConfig original, HttpContext context);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 负载均衡插件
|
||||
/// </summary>
|
||||
public interface ILoadBalancePlugin : IGatewayPlugin
|
||||
{
|
||||
Task<DestinationState> SelectDestinationAsync(
|
||||
IReadOnlyList<DestinationState> destinations,
|
||||
HttpContext context);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user