This commit is contained in:
xiaolipro 2024-02-26 18:09:19 +08:00
commit 769aff3d4f
28 changed files with 562 additions and 0 deletions

25
.dockerignore Normal file
View File

@ -0,0 +1,25 @@
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/.idea
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md

8
.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
bin/
obj/
riderModule.iml
/_ReSharper.Caches/
.idea/
/.vs
/Fake.sln.DotSettings.user

49
InterfaceForward.sln Normal file
View File

@ -0,0 +1,49 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InterfaceForward.AppHost", "src\InterfaceForward.AppHost\InterfaceForward.AppHost.csproj", "{9609CC2D-CC83-4C01-BE36-C0429A06B238}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InterfaceForward.ServiceDefaults", "src\InterfaceForward.ServiceDefaults\InterfaceForward.ServiceDefaults.csproj", "{6DAA9CF1-155A-4FC7-9EAE-7E8FA22CD23A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EA8DF4A8-7618-4C28-BEDC-21629B8B219B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InterfaceForward.Api", "src\InterfaceForward.Api\InterfaceForward.Api.csproj", "{0E2F3A09-4EC4-4A61-85DC-9F9F770C3B65}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "solution items", "solution items", "{670CD43F-BED5-431F-B47D-8CE1D5C1DE71}"
ProjectSection(SolutionItems) = preProject
NuGet.Config = NuGet.Config
common.props = common.props
.gitignore = .gitignore
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InterfaceForward.Domain", "src\InterfaceForward.Domain\InterfaceForward.Domain.csproj", "{AB53F0CC-DE7A-4AE9-B6AA-2A8283B4EB23}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9609CC2D-CC83-4C01-BE36-C0429A06B238}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9609CC2D-CC83-4C01-BE36-C0429A06B238}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9609CC2D-CC83-4C01-BE36-C0429A06B238}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9609CC2D-CC83-4C01-BE36-C0429A06B238}.Release|Any CPU.Build.0 = Release|Any CPU
{6DAA9CF1-155A-4FC7-9EAE-7E8FA22CD23A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6DAA9CF1-155A-4FC7-9EAE-7E8FA22CD23A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6DAA9CF1-155A-4FC7-9EAE-7E8FA22CD23A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6DAA9CF1-155A-4FC7-9EAE-7E8FA22CD23A}.Release|Any CPU.Build.0 = Release|Any CPU
{0E2F3A09-4EC4-4A61-85DC-9F9F770C3B65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E2F3A09-4EC4-4A61-85DC-9F9F770C3B65}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E2F3A09-4EC4-4A61-85DC-9F9F770C3B65}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E2F3A09-4EC4-4A61-85DC-9F9F770C3B65}.Release|Any CPU.Build.0 = Release|Any CPU
{AB53F0CC-DE7A-4AE9-B6AA-2A8283B4EB23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB53F0CC-DE7A-4AE9-B6AA-2A8283B4EB23}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB53F0CC-DE7A-4AE9-B6AA-2A8283B4EB23}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB53F0CC-DE7A-4AE9-B6AA-2A8283B4EB23}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{9609CC2D-CC83-4C01-BE36-C0429A06B238} = {EA8DF4A8-7618-4C28-BEDC-21629B8B219B}
{6DAA9CF1-155A-4FC7-9EAE-7E8FA22CD23A} = {EA8DF4A8-7618-4C28-BEDC-21629B8B219B}
{0E2F3A09-4EC4-4A61-85DC-9F9F770C3B65} = {EA8DF4A8-7618-4C28-BEDC-21629B8B219B}
{AB53F0CC-DE7A-4AE9-B6AA-2A8283B4EB23} = {EA8DF4A8-7618-4C28-BEDC-21629B8B219B}
EndGlobalSection
EndGlobal

6
NuGet.Config Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="xiaolipro.cn" value="https://baget.xiaolipro.cn/v3/index.json" />
</packageSources>
</configuration>

7
common.props Normal file
View File

@ -0,0 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
</PropertyGroup>
</Project>

View File

@ -0,0 +1,23 @@
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["src/InterfaceForward.Api/InterfaceForward.Api.csproj", "src/InterfaceForward.Api/"]
RUN dotnet restore "src/InterfaceForward.Api/InterfaceForward.Api.csproj"
COPY . .
WORKDIR "/src/src/InterfaceForward.Api"
RUN dotnet build "InterfaceForward.Api.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "InterfaceForward.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "InterfaceForward.Api.dll"]

View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<Content Include="..\..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\InterfaceForward.ServiceDefaults\InterfaceForward.ServiceDefaults.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Fake.AspNetCore" Version="8.0.0-preview.3" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,26 @@
using Fake.AspNetCore;
using Fake.Modularity;
namespace InterfaceForward.Api;
[DependsOn(typeof(FakeAspNetCoreModule))]
public class InterfaceForwardApiModule : FakeModule
{
public override void ConfigureServices(ServiceConfigurationContext context)
{
var services = context.Services;
// Add services to the container.
services.AddProblemDetails();
}
public override void ConfigureApplication(ApplicationConfigureContext context)
{
var app = context.GetWebApplication();
// Add Aspire default endpoints.
app.MapDefaultEndpoints();
app.MapGet("/", () => "Hello World!");
}
}

View File

@ -0,0 +1,12 @@
using InterfaceForward.Api;
var builder = WebApplication.CreateSlimBuilder(args);
builder.Services.AddApplication<InterfaceForwardApiModule>();
// Add service defaults & Aspire components.
builder.AddServiceDefaults();
var app = builder.Build();
app.InitializeApplication();
app.Run();

View File

@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:55112",
"sslPort": 44332
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5145",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7210;http://localhost:5145",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspire.Hosting" Version="8.0.0-preview.1.23557.2"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\InterfaceForward.Api\InterfaceForward.Api.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,5 @@
var builder = DistributedApplication.CreateBuilder(args);
builder.AddProject<Projects.InterfaceForward_Api>("apiservice");
builder.Build().Run();

View File

@ -0,0 +1,16 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15177",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16294"
}
}
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}

View File

@ -0,0 +1,39 @@
using System;
using Fake.DomainDrivenDesign.Entities.Auditing;
namespace InterfaceForward.Domain.Aggregates.InterfaceAggregate;
public class InterfaceEntity: FullAuditedEntity<Guid, Guid>
{
public int ServiceProviderId { get; private set; }
public string Name { get; private set; }
public ServiceType ServiceType { get; set; }
public string Code { get; private set; }
public string RequestAddress { get; private set; }
public string RequestMethod { get; private set; }
public RequestContentType RequestContentType { get; private set; }
public ResponseContentType ResponseContentType { get; private set; }
public string FlowCode { get; private set; }
public int Timeout { get; private set; } = 20;
/// <summary>
/// 接口单次请求数量上限默认是1表示不支持批量处理
/// </summary>
public int Limit { get; private set; } = 1;
public int Qps { get; private set; }
/// <summary>
/// 映射后的数据类型
/// </summary>
public ParameterType MappedType { get; set; } = ParameterType.Object;
}

View File

@ -0,0 +1,12 @@
namespace InterfaceForward.Domain.Enumerations;
public class ParameterType(int id, string name) : Enumeration(id, name)
{
public static ParameterType String = new(1, "String");
public static ParameterType Float = new(2, "Float");
public static ParameterType Object = new(3, "Object");
public static ParameterType Boolean = new(4, "Boolean");
public static ParameterType Array = new(5, "Array");
public static ParameterType Integer = new(6, "Integer");
public static ParameterType Date = new(7, "Date");
}

View File

@ -0,0 +1,8 @@
namespace InterfaceForward.Domain.Enumerations;
public class RequestContentType(int id, string name) : Enumeration(id, name)
{
public static RequestContentType Json = new(1, "application/json");
public static RequestContentType Xml = new(2, "application/xml");
public static RequestContentType FormUrlEncoded = new(3, "application/x-www-form-urlencoded");
}

View File

@ -0,0 +1,6 @@
namespace InterfaceForward.Domain.Enumerations;
public class ResponseContentType(int id, string name) : Enumeration(id, name)
{
}

View File

@ -0,0 +1,7 @@
namespace InterfaceForward.Domain.Enumerations;
public class ServiceType(int id, string name) : Enumeration(id, name)
{
public static ServiceType ServiceProvider = new(1, "服务商");
public static ServiceType Platform = new(2, "平台");
}

View File

@ -0,0 +1,4 @@
// Global using directives
global using Fake.DomainDrivenDesign;
global using InterfaceForward.Domain.Enumerations;

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Fake.DomainDrivenDesign" Version="8.0.0-preview.3"/>
</ItemGroup>
</Project>

View File

@ -0,0 +1,8 @@
using System;
namespace InterfaceForward.Domain
{
public class InterfaceForwardDomainModule
{
}
}

View File

@ -0,0 +1,119 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Logging;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
namespace Microsoft.Extensions.Hosting;
public static class Extensions
{
public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBuilder builder)
{
builder.ConfigureOpenTelemetry();
builder.AddDefaultHealthChecks();
builder.Services.AddServiceDiscovery();
builder.Services.ConfigureHttpClientDefaults(http =>
{
// Turn on resilience by default
http.AddStandardResilienceHandler();
// Turn on service discovery by default
http.UseServiceDiscovery();
});
return builder;
}
public static IHostApplicationBuilder ConfigureOpenTelemetry(this IHostApplicationBuilder builder)
{
builder.Logging.AddOpenTelemetry(logging =>
{
logging.IncludeFormattedMessage = true;
logging.IncludeScopes = true;
});
builder.Services.AddOpenTelemetry()
.WithMetrics(metrics =>
{
metrics.AddRuntimeInstrumentation()
.AddBuiltInMeters();
})
.WithTracing(tracing =>
{
if (builder.Environment.IsDevelopment())
{
// We want to view all traces in development
tracing.SetSampler(new AlwaysOnSampler());
}
tracing.AddAspNetCoreInstrumentation()
.AddGrpcClientInstrumentation()
.AddHttpClientInstrumentation();
});
builder.AddOpenTelemetryExporters();
return builder;
}
private static IHostApplicationBuilder AddOpenTelemetryExporters(this IHostApplicationBuilder builder)
{
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
if (useOtlpExporter)
{
builder.Services.Configure<OpenTelemetryLoggerOptions>(logging => logging.AddOtlpExporter());
builder.Services.ConfigureOpenTelemetryMeterProvider(metrics => metrics.AddOtlpExporter());
builder.Services.ConfigureOpenTelemetryTracerProvider(tracing => tracing.AddOtlpExporter());
}
// Uncomment the following lines to enable the Prometheus exporter (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package)
// builder.Services.AddOpenTelemetry()
// .WithMetrics(metrics => metrics.AddPrometheusExporter());
// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.Exporter package)
// builder.Services.AddOpenTelemetry()
// .UseAzureMonitor();
return builder;
}
public static IHostApplicationBuilder AddDefaultHealthChecks(this IHostApplicationBuilder builder)
{
builder.Services.AddHealthChecks()
// Add a default liveness check to ensure app is responsive
.AddCheck("self", () => HealthCheckResult.Healthy(), ["live"]);
return builder;
}
public static WebApplication MapDefaultEndpoints(this WebApplication app)
{
// Uncomment the following line to enable the Prometheus endpoint (requires the OpenTelemetry.Exporter.Prometheus.AspNetCore package)
// app.MapPrometheusScrapingEndpoint();
// All health checks must pass for app to be considered ready to accept traffic after starting
app.MapHealthChecks("/health");
// Only health checks tagged with the "live" tag must pass for app to be considered alive
app.MapHealthChecks("/alive", new HealthCheckOptions
{
Predicate = r => r.Tags.Contains("live")
});
return app;
}
private static MeterProviderBuilder AddBuiltInMeters(this MeterProviderBuilder meterProviderBuilder) =>
meterProviderBuilder.AddMeter(
"Microsoft.AspNetCore.Hosting",
"Microsoft.AspNetCore.Server.Kestrel",
"System.Net.Http");
}

View File

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireSharedProject>true</IsAspireSharedProject>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.0.0"/>
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="8.0.0-preview.1.23557.2"/>
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.7.0-alpha.1"/>
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0-alpha.1"/>
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.6.0-beta.2"/>
<PackageReference Include="OpenTelemetry.Instrumentation.GrpcNetClient" Version="1.6.0-beta.2"/>
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.6.0-beta.2"/>
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.5.1"/>
</ItemGroup>
</Project>

30
src/InterfaceForward.sln Normal file
View File

@ -0,0 +1,30 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.0.0
MinimumVisualStudioVersion = 17.8.0.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InterfaceForward.AppHost", "InterfaceForward.AppHost\InterfaceForward.AppHost.csproj", "{D4540BC1-77C8-407F-9009-CADE4E2A4CD9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InterfaceForward.ServiceDefaults", "InterfaceForward.ServiceDefaults\InterfaceForward.ServiceDefaults.csproj", "{B0AC9CDE-3A63-4AE9-85A9-8854E9EB441E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D4540BC1-77C8-407F-9009-CADE4E2A4CD9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D4540BC1-77C8-407F-9009-CADE4E2A4CD9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D4540BC1-77C8-407F-9009-CADE4E2A4CD9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D4540BC1-77C8-407F-9009-CADE4E2A4CD9}.Release|Any CPU.Build.0 = Release|Any CPU
{B0AC9CDE-3A63-4AE9-85A9-8854E9EB441E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0AC9CDE-3A63-4AE9-85A9-8854E9EB441E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0AC9CDE-3A63-4AE9-85A9-8854E9EB441E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0AC9CDE-3A63-4AE9-85A9-8854E9EB441E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B7073D5C-741D-4DC5-AFDB-C2C67E306A04}
EndGlobalSection
EndGlobal