-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.rs
More file actions
39 lines (32 loc) · 1.32 KB
/
main.rs
File metadata and controls
39 lines (32 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use open_feature::{EvaluationContext, OpenFeature};
use spotify_confidence_sdk::{APIConfig, Confidence, Region};
use spotify_confidence_openfeature_provider::ConfidenceProvider;
#[tokio::main]
#[warn(unused_must_use)]
async fn main() {
let api_config = APIConfig {
api_key: "API_KEY".to_string(),
region: Region::Global,
};
let confidence = Confidence::new(api_config);
let provider = ConfidenceProvider::new(confidence);
let mut api = OpenFeature::singleton_mut().await;
api.set_provider(provider).await;
let client = api.create_client();
let random_number = rand::random::<u64>();
let visitor_id = random_number.to_string();
let context = EvaluationContext::default()
.with_custom_field("visitor_id", visitor_id)
.with_custom_field("user_id", "1111111111");
let details_string = client.get_string_details("hawkflag.message", Some(&context), None).await;
match details_string {
Ok(details) => {
println!("Successfully retrieved flag value: {:?}", details.value);
println!("Flag details: {:?}", details);
}
Err(error) => {
println!("Error retrieving flag: {:?}", error);
println!("This is expected if the flag 'hawkflag.message' doesn't exist in your Confidence project");
}
}
}