mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-22 06:22:50 +08:00
#296 coming up with ideas for this config merging
This commit is contained in:
parent
7ca828836a
commit
3ae2b286ab
@ -5,6 +5,12 @@ using Microsoft.Extensions.Configuration.Memory;
|
|||||||
|
|
||||||
namespace Ocelot.DependencyInjection
|
namespace Ocelot.DependencyInjection
|
||||||
{
|
{
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Configuration.File;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
public static class ConfigurationBuilderExtensions
|
public static class ConfigurationBuilderExtensions
|
||||||
{
|
{
|
||||||
[Obsolete("Please set BaseUrl in ocelot.json GlobalConfiguration.BaseUrl")]
|
[Obsolete("Please set BaseUrl in ocelot.json GlobalConfiguration.BaseUrl")]
|
||||||
@ -21,6 +27,21 @@ namespace Ocelot.DependencyInjection
|
|||||||
|
|
||||||
public static IConfigurationBuilder AddOcelot(this IConfigurationBuilder builder)
|
public static IConfigurationBuilder AddOcelot(this IConfigurationBuilder builder)
|
||||||
{
|
{
|
||||||
|
const string pattern = "(?i)ocelot(.*).json$";
|
||||||
|
|
||||||
|
var reg = new Regex(pattern);
|
||||||
|
|
||||||
|
var files = Directory.GetFiles(".")
|
||||||
|
.Where(path => reg.IsMatch(path))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
var lines = File.ReadAllText(file);
|
||||||
|
var config = JsonConvert.DeserializeObject<FileConfiguration>(lines);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//var load all files with ocelot*.json
|
//var load all files with ocelot*.json
|
||||||
//merge these files into one
|
//merge these files into one
|
||||||
//save it as ocelot.json
|
//save it as ocelot.json
|
||||||
|
@ -70,13 +70,13 @@ namespace Ocelot.UnitTests.DependencyInjection
|
|||||||
};
|
};
|
||||||
|
|
||||||
var globalJson = JsonConvert.SerializeObject(globalConfig);
|
var globalJson = JsonConvert.SerializeObject(globalConfig);
|
||||||
//File.WriteAllText("ocelot.global.json", globalJson);
|
File.WriteAllText("ocelot.global.json", globalJson);
|
||||||
|
|
||||||
var reRouteJson = JsonConvert.SerializeObject(reRoute);
|
var reRouteJson = JsonConvert.SerializeObject(reRoute);
|
||||||
//File.WriteAllText("ocelot.reRoute.json", reRouteJson);
|
File.WriteAllText("ocelot.reRoute.json", reRouteJson);
|
||||||
|
|
||||||
IConfigurationBuilder builder = new ConfigurationBuilder();
|
IConfigurationBuilder builder = new ConfigurationBuilder();
|
||||||
//builder.AddOcelot();
|
builder.AddOcelot();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user