mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-08-04 20:52:27 +08:00
still hacking around
This commit is contained in:
21
src/Ocelot/Controllers/FileConfigurationController.cs
Normal file
21
src/Ocelot/Controllers/FileConfigurationController.cs
Normal file
@ -0,0 +1,21 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Ocelot.Services;
|
||||
|
||||
namespace Ocelot.Controllers
|
||||
{
|
||||
[RouteAttribute("configuration")]
|
||||
public class FileConfigurationController
|
||||
{
|
||||
private IGetFileConfiguration _getFileConfig;
|
||||
|
||||
public FileConfigurationController(IGetFileConfiguration getFileConfig)
|
||||
{
|
||||
_getFileConfig = getFileConfig;
|
||||
}
|
||||
|
||||
public IActionResult Get()
|
||||
{
|
||||
return new OkObjectResult(_getFileConfig.Invoke().Data);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace Ocelot.Controllers
|
||||
{
|
||||
[RouteAttribute("reroutes")]
|
||||
public class ReRoutesController
|
||||
{
|
||||
public IActionResult Get()
|
||||
{
|
||||
return new OkObjectResult("hi from re routes controller");
|
||||
}
|
||||
}
|
||||
}
|
19
src/Ocelot/Services/GetFileConfiguration.cs
Normal file
19
src/Ocelot/Services/GetFileConfiguration.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Responses;
|
||||
|
||||
namespace Ocelot.Services
|
||||
{
|
||||
public class GetFileConfiguration : IGetFileConfiguration
|
||||
{
|
||||
public Response<FileConfiguration> Invoke()
|
||||
{
|
||||
var configFilePath = "configuration.json";
|
||||
var json = File.ReadAllText(configFilePath);
|
||||
var fileConfiguration = JsonConvert.DeserializeObject<FileConfiguration>(json);
|
||||
return new OkResponse<FileConfiguration>(fileConfiguration);
|
||||
}
|
||||
}
|
||||
}
|
10
src/Ocelot/Services/IGetFileConfiguration.cs
Normal file
10
src/Ocelot/Services/IGetFileConfiguration.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using Ocelot.Configuration.File;
|
||||
using Ocelot.Responses;
|
||||
|
||||
namespace Ocelot.Services
|
||||
{
|
||||
public interface IGetFileConfiguration
|
||||
{
|
||||
Response<FileConfiguration> Invoke();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user