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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use std::time::Duration;
#[cfg(feature = "use_tokio")]
use reqwest::Client;
use tracing::info;
use url::Url;
#[derive(Debug, Clone)]
pub struct FPConfig {
pub remote_url: Url,
pub toggles_url: Option<Url>,
pub events_url: Option<Url>,
pub server_sdk_key: String,
pub refresh_interval: Duration,
#[cfg(feature = "use_tokio")]
pub http_client: Option<Client>,
pub start_wait: Option<Duration>,
}
#[derive(Debug, Clone)]
pub(crate) struct Config {
pub toggles_url: Url,
pub events_url: Url,
pub server_sdk_key: String,
pub refresh_interval: Duration,
#[cfg(feature = "use_tokio")]
pub http_client: Option<Client>,
pub start_wait: Option<Duration>,
}
impl Default for FPConfig {
fn default() -> Self {
Self {
server_sdk_key: "".to_owned(),
remote_url: Url::parse("http://127.0.0.1:8080").unwrap(),
toggles_url: None,
events_url: None,
refresh_interval: Duration::from_secs(5),
start_wait: None,
#[cfg(feature = "use_tokio")]
http_client: None,
}
}
}
impl Default for Config {
fn default() -> Self {
Self {
server_sdk_key: "".to_owned(),
toggles_url: Url::parse("http://127.0.0.1:8080").unwrap(),
events_url: Url::parse("http://127.0.0.1:8080").unwrap(),
refresh_interval: Duration::from_secs(5),
start_wait: None,
#[cfg(feature = "use_tokio")]
http_client: None,
}
}
}
impl FPConfig {
pub(crate) fn build(&self) -> Config {
info!("build_config from {:?}", self);
let remote_url = self.remote_url.to_string();
let remote_url = match remote_url.ends_with('/') {
true => remote_url,
false => remote_url + "/",
};
let toggles_url = match &self.toggles_url {
None => {
Url::parse(&(remote_url.clone() + "api/server-sdk/toggles")).expect("invalid url")
}
Some(url) => url.to_owned(),
};
let events_url = match &self.events_url {
None => Url::parse(&(remote_url + "api/events")).expect("invalid url"),
Some(url) => url.to_owned(),
};
Config {
toggles_url,
events_url,
server_sdk_key: self.server_sdk_key.clone(),
refresh_interval: self.refresh_interval,
start_wait: self.start_wait,
#[cfg(feature = "use_tokio")]
http_client: self.http_client.clone(),
}
}
}