You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 line
1.1KB

  1. var builder = WebApplication.CreateBuilder(args);
  2. builder.WebHost.UseUrls("http://0.0.0.0:9090");
  3. // Add services to the container.
  4. // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
  5. builder.Services.AddEndpointsApiExplorer();
  6. builder.Services.AddSwaggerGen();
  7. var app = builder.Build();
  8. // Configure the HTTP request pipeline.
  9. if (app.Environment.IsDevelopment())
  10. {
  11. app.UseSwagger();
  12. app.UseSwaggerUI();
  13. }
  14. app.UseHttpsRedirection();
  15. var summaries = new[]
  16. {
  17. "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
  18. };
  19. app.MapGet("/weatherforecast", () =>
  20. {
  21. var forecast = Enumerable.Range(1, 5).Select(index =>
  22. new WeatherForecast
  23. (
  24. DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
  25. Random.Shared.Next(-20, 55),
  26. summaries[Random.Shared.Next(summaries.Length)]
  27. ))
  28. .ToArray();
  29. return forecast;
  30. })
  31. .WithName("GetWeatherForecast")
  32. .WithOpenApi();
  33. app.Run();
  34. record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
  35. {
  36. public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
  37. }