添加项目文件。
This commit is contained in:
parent
4db2bb90e0
commit
0c83a19d21
|
|
@ -0,0 +1,3 @@
|
|||
<Solution>
|
||||
<Project Path="MicoService.Demo/MicoService.Demo.csproj" />
|
||||
</Solution>
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MicoService.Demo.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class WeatherForecastController : ControllerBase
|
||||
{
|
||||
private static readonly string[] Summaries =
|
||||
[
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
];
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public WeatherForecastController(IConfiguration configuration)
|
||||
{
|
||||
this._configuration = configuration;
|
||||
}
|
||||
|
||||
[HttpGet(Name = "GetWeatherForecast")]
|
||||
public IEnumerable<WeatherForecast> Get()
|
||||
{
|
||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
||||
{
|
||||
Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
TemperatureC = Random.Shared.Next(-20, 55),
|
||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
[HttpGet("config/{key}")]
|
||||
public string GetConfig(string key)
|
||||
{
|
||||
return _configuration[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.2" />
|
||||
<PackageReference Include="nacos-sdk-csharp.AspNetCore" Version="1.3.10" />
|
||||
<PackageReference Include="nacos-sdk-csharp.Extensions.Configuration" Version="1.3.10" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
|
||||
using Nacos.AspNetCore.V2;
|
||||
using Nacos.V2.DependencyInjection;
|
||||
|
||||
namespace MicoService.Demo
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
|
||||
builder.Host.UseNacosConfig("nacos");
|
||||
builder.Services.AddNacosV2Config(builder.Configuration);
|
||||
|
||||
|
||||
builder.Services.AddNacosAspNet(builder.Configuration);
|
||||
builder.Services.AddNacosV2Naming(builder.Configuration);
|
||||
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi();
|
||||
}
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "http://localhost:5252",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
namespace MicoService.Demo
|
||||
{
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"nacos": {
|
||||
// Nacos 配置中心的配置
|
||||
"Namespace": "685d64ce-d088-400f-8cfe-a669a89015d0", // 你的命名空间ID
|
||||
"ServerAddresses": [ "http://192.168.2.9:8848" ], // 自建Nacos地址(去掉末尾/,避免解析问题)
|
||||
"UserName": "nacos", // 你的Nacos用户名
|
||||
"Password": "qwe123!@#", // 你的Nacos密码
|
||||
"Group": "DEFAULT_GROUP", // 默认配置分组,可按需修改
|
||||
"Listeners": [
|
||||
{
|
||||
"Optional": false,
|
||||
"DataId": "demo_dev",
|
||||
"Group": "DEFAULT_GROUP"
|
||||
}
|
||||
],
|
||||
|
||||
// Ncaos 注册中心的配置
|
||||
"DefaultTimeOut": 15000,
|
||||
"ListenInterval": 1000,
|
||||
"ServiceName": "Mico_Demo1",
|
||||
"GroupName": "DEFAULT_GROUP",
|
||||
"RegisterEnabled": true,
|
||||
"InstanceEnabled": true,
|
||||
"Ephemeral": true,
|
||||
"ConfigUseRpc": true,
|
||||
"NamingUseRpc": true,
|
||||
"LBStrategy": "WeightRandom" //WeightRandom WeightRoundRobin
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Loading…
Reference in New Issue