mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-07-31 08:35:58 +08:00
after hours of pissing around on the mac...gave up..so got this configured how i wanted in VS2015 now to see if it works on the mac
This commit is contained in:
12
src/Ocelot.Library/Infrastructure/Responses/Error.cs
Normal file
12
src/Ocelot.Library/Infrastructure/Responses/Error.cs
Normal file
@ -0,0 +1,12 @@
|
||||
namespace Ocelot.Library.Infrastructure.Responses
|
||||
{
|
||||
public abstract class Error
|
||||
{
|
||||
public Error(string message)
|
||||
{
|
||||
Message = message;
|
||||
}
|
||||
|
||||
public string Message { get; private set; }
|
||||
}
|
||||
}
|
11
src/Ocelot.Library/Infrastructure/Responses/ErrorResponse.cs
Normal file
11
src/Ocelot.Library/Infrastructure/Responses/ErrorResponse.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Responses
|
||||
{
|
||||
public class ErrorResponse : Response
|
||||
{
|
||||
public ErrorResponse(List<Error> errors) : base(errors)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Responses
|
||||
{
|
||||
public class ErrorResponse<T> : Response<T>
|
||||
{
|
||||
public ErrorResponse(List<Error> errors) : base(errors)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace Ocelot.Library.Infrastructure.Responses
|
||||
{
|
||||
public class OkResponse : Response
|
||||
{
|
||||
public OkResponse()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace Ocelot.Library.Infrastructure.Responses
|
||||
{
|
||||
public class OkResponse<T> : Response<T>
|
||||
{
|
||||
public OkResponse(T data) : base(data)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
19
src/Ocelot.Library/Infrastructure/Responses/Response.cs
Normal file
19
src/Ocelot.Library/Infrastructure/Responses/Response.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Responses
|
||||
{
|
||||
public abstract class Response
|
||||
{
|
||||
protected Response()
|
||||
{
|
||||
Errors = new List<Error>();
|
||||
}
|
||||
|
||||
protected Response(List<Error> errors)
|
||||
{
|
||||
Errors = errors ?? new List<Error>();
|
||||
}
|
||||
|
||||
public List<Error> Errors { get; private set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Responses
|
||||
{
|
||||
public abstract class Response<T> : Response
|
||||
{
|
||||
protected Response(T data)
|
||||
{
|
||||
Data = data;
|
||||
}
|
||||
|
||||
protected Response(List<Error> errors) : base(errors)
|
||||
{
|
||||
}
|
||||
|
||||
public T Data { get; private set; }
|
||||
}
|
||||
}
|
10
src/Ocelot.Library/Infrastructure/Router/IRouterService.cs
Normal file
10
src/Ocelot.Library/Infrastructure/Router/IRouterService.cs
Normal file
@ -0,0 +1,10 @@
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Router
|
||||
{
|
||||
public interface IRouterService
|
||||
{
|
||||
Response AddRoute(string apiKey, string upstreamApiBaseUrl);
|
||||
Response<Route> GetRoute(string apiKey);
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Router
|
||||
{
|
||||
public class InMemoryRouterService : IRouterService
|
||||
{
|
||||
private readonly Dictionary<string, string> _routes;
|
||||
public InMemoryRouterService()
|
||||
{
|
||||
_routes = new Dictionary<string,string>();
|
||||
}
|
||||
public Response AddRoute(string apiKey, string upstreamApiBaseUrl)
|
||||
{
|
||||
if(_routes.ContainsKey(apiKey))
|
||||
{
|
||||
return new ErrorResponse(new List<Error>(){new RouteKeyAlreadyExists("This key has already been used")});
|
||||
}
|
||||
|
||||
_routes.Add(apiKey, upstreamApiBaseUrl);
|
||||
|
||||
return new OkResponse();
|
||||
}
|
||||
|
||||
public Response<Route> GetRoute(string apiKey)
|
||||
{
|
||||
Console.WriteLine("looking for {0}", apiKey);
|
||||
string upstreamApiBaseUrl = null;
|
||||
|
||||
if(_routes.TryGetValue(apiKey, out upstreamApiBaseUrl))
|
||||
{
|
||||
return new OkResponse<Route>(new Route(apiKey, upstreamApiBaseUrl));
|
||||
}
|
||||
|
||||
Console.WriteLine("Couldnt find it");
|
||||
|
||||
return new ErrorResponse<Route>(new List<Error>(){new RouteKeyDoesNotExist("This key does not exist")});
|
||||
}
|
||||
}
|
||||
}
|
14
src/Ocelot.Library/Infrastructure/Router/Route.cs
Normal file
14
src/Ocelot.Library/Infrastructure/Router/Route.cs
Normal file
@ -0,0 +1,14 @@
|
||||
namespace Ocelot.Library.Infrastructure.Router
|
||||
{
|
||||
public class Route
|
||||
{
|
||||
public Route(string apiKey, string upstreamRoute)
|
||||
{
|
||||
ApiKey = apiKey;
|
||||
UpstreamRoute = upstreamRoute;
|
||||
}
|
||||
|
||||
public string ApiKey {get;private set;}
|
||||
public string UpstreamRoute {get;private set;}
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Router
|
||||
{
|
||||
public class RouteKeyAlreadyExists : Error
|
||||
{
|
||||
public RouteKeyAlreadyExists(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using Ocelot.Library.Infrastructure.Responses;
|
||||
|
||||
namespace Ocelot.Library.Infrastructure.Router
|
||||
{
|
||||
public class RouteKeyDoesNotExist : Error
|
||||
{
|
||||
public RouteKeyDoesNotExist(string message)
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user