Esempio n. 1
0
        public string GenOcelotJsonFile(List <ServiceDef> svcDefs)
        {
            var rootCfg = new CfgRootobject()
            {
                GlobalConfiguration = new Globalconfiguration()
                {
                    BaseUrl = "http://localhost", RequestIdKey = LogHeaderMiddleware.CorrelationHeader
                }
            };
            var reroutes         = new List <Reroute>();
            var swaggerendpoints = new List <Swaggerendpoint>();

            foreach (var svcDef in svcDefs)
            {
                var svcAliasName = svcDef.Host.ToLower();                  //SwaggerExt.ResolveServiceName(svcDef.Host);
                var everything   = "{everything}";
                var host         = svcDef.Host.Replace(".", "").ToLower(); //因K8S service name限制
                var route        = new Reroute()
                {
                    DownstreamHostAndPorts = new Downstreamhostandport[] { new Downstreamhostandport()
                                                                           {
                                                                               Host = host, Port = 80
                                                                           } }
                    , DownstreamScheme       = "http"
                    , DownstreamPathTemplate = $"/api/{everything}"
                    , UpstreamPathTemplate   = $"/{svcAliasName}/api/{everything}"
                    , UpstreamHttpMethod     = new string[] { "POST", "PUT", "GET", "DELETE" }
                    , SwaggerKey             = svcAliasName
                };
                //foreach (var ver in svcDef.Versions)
                {
                    var ver             = svcDef.Versions.Last();
                    var swaggerPath     = string.Format(SwaggerExt.SwaggerPathTemplate, ver);
                    var swaggerendpoint = new Swaggerendpoint()
                    {
                        Key      = svcAliasName
                        , Config = new Config[] { new Config()
                                                  {
                                                      Name = svcAliasName, Version = $"v{ver}", Url = $"http://{svcDef.Host}{swaggerPath}"
                                                  } }
                    };
                    swaggerendpoints.Add(swaggerendpoint);
                }

                reroutes.Add(route);
            }
            rootCfg.ReRoutes         = reroutes.ToArray();
            rootCfg.SwaggerEndPoints = swaggerendpoints.ToArray();
            var ts = new JsonNetTransfer();

            ts.NeedFormatting = true;
            var jsonPath = GetOcelotJsonPath();

            ts.Save(rootCfg, jsonPath);
            return(jsonPath);
        }
Esempio n. 2
0
        public void T_SaveTestData()
        {// TODO: Add Testing logic here
            var ts   = new JsonNetTransfer();
            var data = new SvcInstance();

            data.SpecId = "SPIP";
            data.Characteristics.Add(new SvcCharacteristic("id_1", "case_001"));
            data.Characteristics.Add(new SvcCharacteristic("id_2", "受理"));
            data.Characteristics.Add(new SvcCharacteristic("id_3", "訂單"));
            ts.Save(data, @"d:\a.json");
        }