mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 13:50:49 +08:00 
			
		
		
		
	编写k8s测试例子
This commit is contained in:
		@@ -0,0 +1,45 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Microsoft.AspNetCore.Mvc;
 | 
			
		||||
 | 
			
		||||
namespace DownstreamService.Controllers
 | 
			
		||||
{
 | 
			
		||||
    [Route("api/[controller]")]
 | 
			
		||||
    [ApiController]
 | 
			
		||||
    public class ValuesController : ControllerBase
 | 
			
		||||
    {
 | 
			
		||||
        // GET api/values
 | 
			
		||||
        [HttpGet]
 | 
			
		||||
        public ActionResult<IEnumerable<string>> Get()
 | 
			
		||||
        {
 | 
			
		||||
            return new string[] { "value1", "value2" };
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // GET api/values/5
 | 
			
		||||
        [HttpGet("{id}")]
 | 
			
		||||
        public ActionResult<string> Get(int id)
 | 
			
		||||
        {
 | 
			
		||||
            return "value";
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // POST api/values
 | 
			
		||||
        [HttpPost]
 | 
			
		||||
        public void Post([FromBody] string value)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // PUT api/values/5
 | 
			
		||||
        [HttpPut("{id}")]
 | 
			
		||||
        public void Put(int id, [FromBody] string value)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // DELETE api/values/5
 | 
			
		||||
        [HttpDelete("{id}")]
 | 
			
		||||
        public void Delete(int id)
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										19
									
								
								samples/OelotKube/DownstreamService/Dockerfile
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								samples/OelotKube/DownstreamService/Dockerfile
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,19 @@
 | 
			
		||||
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
 | 
			
		||||
WORKDIR /app
 | 
			
		||||
EXPOSE 80
 | 
			
		||||
 | 
			
		||||
FROM microsoft/dotnet:2.2-sdk AS build
 | 
			
		||||
WORKDIR /src
 | 
			
		||||
COPY ["DownstreamService/DownstreamService.csproj", "DownstreamService/"]
 | 
			
		||||
RUN dotnet restore "DownstreamService/DownstreamService.csproj"
 | 
			
		||||
COPY . .
 | 
			
		||||
WORKDIR "/src/DownstreamService"
 | 
			
		||||
RUN dotnet build "DownstreamService.csproj" -c Release -o /app
 | 
			
		||||
 | 
			
		||||
FROM build AS publish
 | 
			
		||||
RUN dotnet publish "DownstreamService.csproj" -c Release -o /app
 | 
			
		||||
 | 
			
		||||
FROM base AS final
 | 
			
		||||
WORKDIR /app
 | 
			
		||||
COPY --from=publish /app .
 | 
			
		||||
ENTRYPOINT ["dotnet", "DownstreamService.dll"]
 | 
			
		||||
							
								
								
									
										15
									
								
								samples/OelotKube/DownstreamService/DownstreamService.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								samples/OelotKube/DownstreamService/DownstreamService.csproj
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
<Project Sdk="Microsoft.NET.Sdk.Web">
 | 
			
		||||
 | 
			
		||||
  <PropertyGroup>
 | 
			
		||||
    <TargetFramework>netcoreapp2.1</TargetFramework>
 | 
			
		||||
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
 | 
			
		||||
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
 | 
			
		||||
  </PropertyGroup>
 | 
			
		||||
 | 
			
		||||
  <ItemGroup>
 | 
			
		||||
    <PackageReference Include="Microsoft.AspNetCore.App" />
 | 
			
		||||
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
 | 
			
		||||
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.1.1" />
 | 
			
		||||
  </ItemGroup>
 | 
			
		||||
 | 
			
		||||
</Project>
 | 
			
		||||
							
								
								
									
										24
									
								
								samples/OelotKube/DownstreamService/Program.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								samples/OelotKube/DownstreamService/Program.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.IO;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Microsoft.AspNetCore;
 | 
			
		||||
using Microsoft.AspNetCore.Hosting;
 | 
			
		||||
using Microsoft.Extensions.Configuration;
 | 
			
		||||
using Microsoft.Extensions.Logging;
 | 
			
		||||
 | 
			
		||||
namespace DownstreamService
 | 
			
		||||
{
 | 
			
		||||
    public class Program
 | 
			
		||||
    {
 | 
			
		||||
        public static void Main(string[] args)
 | 
			
		||||
        {
 | 
			
		||||
            CreateWebHostBuilder(args).Build().Run();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
 | 
			
		||||
            WebHost.CreateDefaultBuilder(args)
 | 
			
		||||
                .UseStartup<Startup>();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,35 @@
 | 
			
		||||
{
 | 
			
		||||
  "iisSettings": {
 | 
			
		||||
    "windowsAuthentication": false,
 | 
			
		||||
    "anonymousAuthentication": true,
 | 
			
		||||
    "iisExpress": {
 | 
			
		||||
      "applicationUrl": "http://localhost:56411",
 | 
			
		||||
      "sslPort": 0
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "$schema": "http://json.schemastore.org/launchsettings.json",
 | 
			
		||||
  "profiles": {
 | 
			
		||||
    "IIS Express": {
 | 
			
		||||
      "commandName": "IISExpress",
 | 
			
		||||
      "launchBrowser": true,
 | 
			
		||||
      "launchUrl": "api/values",
 | 
			
		||||
      "environmentVariables": {
 | 
			
		||||
        "ASPNETCORE_ENVIRONMENT": "Development"
 | 
			
		||||
      }
 | 
			
		||||
    },
 | 
			
		||||
    "DownstreamService": {
 | 
			
		||||
      "commandName": "Project",
 | 
			
		||||
      "launchBrowser": true,
 | 
			
		||||
      "launchUrl": "api/values",
 | 
			
		||||
      "environmentVariables": {
 | 
			
		||||
        "ASPNETCORE_ENVIRONMENT": "Development"
 | 
			
		||||
      },
 | 
			
		||||
      "applicationUrl": "http://localhost:5000"
 | 
			
		||||
    },
 | 
			
		||||
    "Docker": {
 | 
			
		||||
      "commandName": "Docker",
 | 
			
		||||
      "launchBrowser": true,
 | 
			
		||||
      "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/api/values"
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										41
									
								
								samples/OelotKube/DownstreamService/Startup.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								samples/OelotKube/DownstreamService/Startup.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,41 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using Microsoft.AspNetCore.Builder;
 | 
			
		||||
using Microsoft.AspNetCore.Hosting;
 | 
			
		||||
using Microsoft.AspNetCore.Mvc;
 | 
			
		||||
using Microsoft.Extensions.Configuration;
 | 
			
		||||
using Microsoft.Extensions.DependencyInjection;
 | 
			
		||||
using Microsoft.Extensions.Logging;
 | 
			
		||||
using Microsoft.Extensions.Options;
 | 
			
		||||
 | 
			
		||||
namespace DownstreamService
 | 
			
		||||
{
 | 
			
		||||
    public class Startup
 | 
			
		||||
    {
 | 
			
		||||
        public Startup(IConfiguration configuration)
 | 
			
		||||
        {
 | 
			
		||||
            Configuration = configuration;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IConfiguration Configuration { get; }
 | 
			
		||||
 | 
			
		||||
        // This method gets called by the runtime. Use this method to add services to the container.
 | 
			
		||||
        public void ConfigureServices(IServiceCollection services)
 | 
			
		||||
        {
 | 
			
		||||
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
 | 
			
		||||
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
 | 
			
		||||
        {
 | 
			
		||||
            if (env.IsDevelopment())
 | 
			
		||||
            {
 | 
			
		||||
                app.UseDeveloperExceptionPage();
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            app.UseMvc();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,9 @@
 | 
			
		||||
{
 | 
			
		||||
  "Logging": {
 | 
			
		||||
    "LogLevel": {
 | 
			
		||||
      "Default": "Debug",
 | 
			
		||||
      "System": "Information",
 | 
			
		||||
      "Microsoft": "Information"
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										8
									
								
								samples/OelotKube/DownstreamService/appsettings.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								samples/OelotKube/DownstreamService/appsettings.json
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
{
 | 
			
		||||
  "Logging": {
 | 
			
		||||
    "LogLevel": {
 | 
			
		||||
      "Default": "Warning"
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  "AllowedHosts": "*"
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user