add synchronous variant of FuncEndpointDelegate
This commit is contained in:
parent
c6d99ea9be
commit
523cdb8ad2
2 changed files with 16 additions and 4 deletions
|
@ -2,13 +2,15 @@
|
|||
|
||||
namespace Uwaa.HTTP.Routing;
|
||||
|
||||
public delegate Task<HttpResponse?> FuncEndpointDelegate(HttpRequest req);
|
||||
public delegate Task<HttpResponse?> FuncEndpointDelegateAsync(HttpRequest req);
|
||||
|
||||
public delegate HttpResponse? FuncEndpointDelegate(HttpRequest req);
|
||||
|
||||
public class FuncEndpoint : RouterBase
|
||||
{
|
||||
public FuncEndpointDelegate Function;
|
||||
public FuncEndpointDelegateAsync Function;
|
||||
|
||||
public FuncEndpoint(FuncEndpointDelegate function)
|
||||
public FuncEndpoint(FuncEndpointDelegateAsync function)
|
||||
{
|
||||
Function = function;
|
||||
}
|
||||
|
|
|
@ -43,7 +43,17 @@ public class Router : RouterBase
|
|||
/// <summary>
|
||||
/// Adds an endpoint to the router on the given sub path.
|
||||
/// </summary>
|
||||
public void Add(string? key, FuncEndpointDelegate func) => Routes.Add(new Route(key, new FuncEndpoint(func)));
|
||||
public void Add(string? key, FuncEndpointDelegateAsync func) => Routes.Add(new Route(key, new FuncEndpoint(func)));
|
||||
|
||||
/// <summary>
|
||||
/// Adds a wildcard endpoint to the router.
|
||||
/// </summary>
|
||||
public void Add(FuncEndpointDelegateAsync func) => Add(null, func);
|
||||
|
||||
/// <summary>
|
||||
/// Adds an endpoint to the router on the given sub path.
|
||||
/// </summary>
|
||||
public void Add(string? key, FuncEndpointDelegate func) => Add(key, req => Task.FromResult(func(req)));
|
||||
|
||||
/// <summary>
|
||||
/// Adds a wildcard endpoint to the router.
|
||||
|
|
Loading…
Reference in a new issue