use std::time::Duration;
use tonic::transport::{ClientTlsConfig, Endpoint, Error};
pub fn configure_endpoint(addr: &str) -> Result<Endpoint, Error> {
let mut endpoint = Endpoint::new(addr.to_string())?
.timeout(Duration::from_secs(60))
.connect_timeout(Duration::from_secs(15))
.keep_alive_while_idle(true)
.http2_keep_alive_interval(Duration::from_secs(15))
.keep_alive_timeout(Duration::from_secs(15))
.tcp_keepalive(Some(Duration::from_secs(60)))
.tcp_nodelay(true);
if addr.starts_with("https://") {
let tls_config = ClientTlsConfig::new().with_enabled_roots();
endpoint = endpoint.tls_config(tls_config)?;
}
Ok(endpoint)
}