how to write transforms value in class #2330
Answered
by
Tratcher
dantemayson
asked this question in
General
-
hi,I want to write the equivalent of appsetting in the form of code. The only problem I have is that I don't know how to write the value of transforms in the form of code.
Programmatic Configuration public class YarpProxyConfig : IProxyConfig
{
readonly List<RouteConfig> _routes;
readonly List<ClusterConfig> _clusters;
readonly CancellationChangeToken _changeToken;
readonly CancellationTokenSource _cts = new CancellationTokenSource();
public YarpProxyConfig()
{
_routes = GenerateRoutes();
_clusters = GenerateClusters();
_cts = new CancellationTokenSource();
_changeToken = new CancellationChangeToken(_cts.Token);
}
public IReadOnlyList<RouteConfig> Routes => _routes;
public IReadOnlyList<ClusterConfig> Clusters => _clusters;
public IChangeToken ChangeToken => _changeToken;
private List<ClusterConfig> GenerateClusters()
{
var collection = new List<ClusterConfig>();
collection.Add(new ClusterConfig()
{
ClusterId = "FirstCluster",
Destinations = new Dictionary<string, DestinationConfig>{
{
"server", new DestinationConfig()
{
Address = "http://localhost:5167"
}
}
}
});
return collection;
}
private List<RouteConfig> GenerateRoutes()
{
var collection = new List<RouteConfig>();
collection.Add(new RouteConfig()
{
RouteId="Route1",
ClusterId = "FirstCluster",
Match = new RouteMatch()
{
Path = "/api/{**catch-all}"
},
Transforms= //? == "PathPattern": "{**catch-all}"
});
return collection;
}
} The equivalent of this code in C#
Transforms= ? |
Beta Was this translation helpful? Give feedback.
Answered by
Tratcher
Nov 15, 2023
Replies: 1 comment 2 replies
-
The raw syntax is a bit ugly, here's a helper that makes it easier: |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
karelz
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The raw syntax is a bit ugly, here's a helper that makes it easier:
reverse-proxy/src/ReverseProxy/Transforms/PathTransformExtensions.cs
Line 97 in 47231e9