Skip to content

Commit

Permalink
Move the original mod.rs to ws.rs
Browse files Browse the repository at this point in the history
Introduce the meta Client that will instantiate the original Ws client or the
new Http upstream client
  • Loading branch information
cesar-startale committed Jul 19, 2024
1 parent dbbd473 commit bd8c52a
Show file tree
Hide file tree
Showing 3 changed files with 592 additions and 470 deletions.
30 changes: 7 additions & 23 deletions src/extensions/client/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,16 @@ pub struct HttpClient {
}

impl HttpClient {
pub fn new(endpoints: Vec<String>) -> Result<(Option<Self>, Vec<String>), Error> {
let mut other_urls = vec![];
pub fn new(endpoints: &[String]) -> Result<Self, Error> {
let clients = endpoints
.into_iter()
.filter_map(|url| {
let t_url = url.to_lowercase();
if t_url.starts_with("http://") || t_url.starts_with("https://") {
Some(RpcClient::builder().build(url))
} else {
other_urls.push(url);
None
}
})
.iter()
.map(|url| RpcClient::builder().build(url))
.collect::<Result<Vec<_>, _>>()?;

if clients.is_empty() {
Ok((None, other_urls))
} else {
Ok((
Some(Self {
clients,
last_sent: AtomicUsize::new(0),
}),
other_urls,
))
}
Ok(Self {
clients,
last_sent: AtomicUsize::new(0),
})
}

/// Sends a request to one of the clients
Expand Down
Loading

0 comments on commit bd8c52a

Please sign in to comment.