| /* | |
| * Licensed to the Apache Software Foundation (ASF) under one or more | |
| * contributor license agreements. See the NOTICE file distributed with | |
| * this work for additional information regarding copyright ownership. | |
| * The ASF licenses this file to You under the Apache License, Version 2.0 | |
| * (the "License"); you may not use this file except in compliance with | |
| * the License. You may obtain a copy of the License at | |
| * | |
| * http://www.apache.org/licenses/LICENSE-2.0 | |
| * | |
| * Unless required by applicable law or agreed to in writing, software | |
| * distributed under the License is distributed on an "AS IS" BASIS, | |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| * See the License for the specific language governing permissions and | |
| * limitations under the License. | |
| */ | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using Apache.ShenYu.Client.Attributes; | |
| using Microsoft.AspNetCore.Hosting.Server; | |
| using Microsoft.AspNetCore.Hosting.Server.Features; | |
| using Microsoft.AspNetCore.Mvc; | |
| using Microsoft.Extensions.Logging; | |
| namespace AspNetCoreExample.Controllers | |
| { | |
| [ApiController] | |
| [Route("[controller]")] | |
| public class TemplateController | |
| { | |
| private static readonly string[] Summaries = new[] | |
| { | |
| "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | |
| }; | |
| private readonly ILogger<WeatherForecastController> _logger; | |
| public TemplateController(ILogger<WeatherForecastController> logger, IServer server) | |
| { | |
| this._logger = logger; | |
| var addresses = server.Features.Get<IServerAddressesFeature>().Addresses; | |
| } | |
| [HttpGet("hello")] | |
| [ShenyuClient("hello")] | |
| public IEnumerable<WeatherForecast> GetTest() | |
| { | |
| var rng = new Random(); | |
| return Enumerable.Range(1, 5).Select(index => new WeatherForecast | |
| { | |
| Date = DateTime.Now.AddDays(index), | |
| TemperatureC = rng.Next(-20, 55), | |
| Summary = Summaries[rng.Next(Summaries.Length)] | |
| }) | |
| .ToArray(); | |
| } | |
| [HttpPost] | |
| public IEnumerable<WeatherForecast> PostTest() | |
| { | |
| var rng = new Random(); | |
| return Enumerable.Range(1, 5).Select(index => new WeatherForecast | |
| { | |
| Date = DateTime.Now.AddDays(index), | |
| TemperatureC = rng.Next(-20, 55), | |
| Summary = Summaries[rng.Next(Summaries.Length)] | |
| }) | |
| .ToArray(); | |
| } | |
| } | |
| } |