mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 19:50:49 +08:00 
			
		
		
		
	#296 coming up with ideas for this config merging
This commit is contained in:
		@@ -5,6 +5,12 @@ using Microsoft.Extensions.Configuration.Memory;
 | 
			
		||||
 | 
			
		||||
namespace Ocelot.DependencyInjection
 | 
			
		||||
{
 | 
			
		||||
    using System.IO;
 | 
			
		||||
    using System.Linq;
 | 
			
		||||
    using System.Text.RegularExpressions;
 | 
			
		||||
    using Configuration.File;
 | 
			
		||||
    using Newtonsoft.Json;
 | 
			
		||||
 | 
			
		||||
    public static class ConfigurationBuilderExtensions
 | 
			
		||||
    {
 | 
			
		||||
        [Obsolete("Please set BaseUrl in ocelot.json GlobalConfiguration.BaseUrl")]
 | 
			
		||||
@@ -21,6 +27,21 @@ namespace Ocelot.DependencyInjection
 | 
			
		||||
 | 
			
		||||
        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
 | 
			
		||||
            //merge these files into one
 | 
			
		||||
            //save it as ocelot.json
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user