Crate unleash_proxy
source · [−]Expand description
Copyright 2020-2022 Cognite AS
The included binary unleash-proxy
is equivalent to this code:
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Add deployment specific concerns here
env_logger::init();
unleash_proxy::main().await
}
Here is an example adding a custom strategy:
use std::collections::{HashMap, HashSet};
use std::hash::BuildHasher;
use serde::{Deserialize, Serialize};
use unleash_api_client::context::Context;
use unleash_api_client::strategy;
pub fn example<S: BuildHasher>(
parameters: Option<HashMap<String, String, S>>,
) -> strategy::Evaluate {
let mut items: HashSet<String> = HashSet::new();
if let Some(parameters) = parameters {
if let Some(item_list) = parameters.get("exampleParameter") {
for item in item_list.split(',') {
items.insert(item.trim().into());
}
}
}
Box::new(move |context: &Context| -> bool {
matches!(
context
.properties
.get("exampleProperty")
.map(|item| items.contains(item)),
Some(true)
)
})
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// Add deployment specific concerns here
env_logger::init();
unleash_proxy::ProxyBuilder::default().
strategy("example", Box::new(&example)).execute().await
}
Structs
Permits customising the Proxy behaviour. See the crate
level docs for examples.