12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using Dapr.Client;
- using Microsoft.AspNetCore.Mvc;
- namespace MyBackEnd.Controllers
- {
- [ApiController]
- [Route("[controller]")]
- public class WeatherForecastController : ControllerBase
- {
- private static readonly string[] Summaries = new[]
- {
- "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
- };
- private readonly DaprClient _daprClient;
- private readonly ILogger<WeatherForecastController> _logger;
- public WeatherForecastController(
- DaprClient daprClient,
- ILogger<WeatherForecastController> logger)
- {
- _daprClient = daprClient;
- _logger = logger;
- }
- [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("remote-time")]
- public async Task<string> GetTime()
- {
- var r = await _daprClient.InvokeMethodAsync<Rsp>(
- HttpMethod.Get,
- "hotline",
- "api/v1/Test/time",
- HttpContext.RequestAborted);
- return r.Result;
- }
- }
- public class Rsp
- {
- //{
- // "result": "Wednesday, 19 July 2023 14:32:43",
- // "code": 0,
- // "message": null,
- // "error": null
- //}
- public string Result { get; set; }
- public int Code { get; set; }
- public string Message { get; set; }
- public string Error { get; set; }
- }
- }
|