feat: init
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
use crate::config::AppConfig;
|
||||
use crate::error::AppResult;
|
||||
|
||||
impl AppConfig {
|
||||
pub fn etcd_endpoints(&self) -> AppResult<Vec<String>> {
|
||||
match self.get_env::<String>("APP_ETCD_ENDPOINTS")? {
|
||||
Some(s) if !s.is_empty() => Ok(s
|
||||
.split(',')
|
||||
.map(|u| u.trim().to_string())
|
||||
.filter(|u| !u.is_empty())
|
||||
.collect()),
|
||||
_ => Ok(vec!["http://localhost:2379".to_string()]),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn etcd_username(&self) -> AppResult<Option<String>> {
|
||||
self.get_env::<String>("APP_ETCD_USERNAME")
|
||||
}
|
||||
|
||||
pub fn etcd_password(&self) -> AppResult<Option<String>> {
|
||||
self.get_env::<String>("APP_ETCD_PASSWORD")
|
||||
}
|
||||
|
||||
pub fn etcd_ca_cert_path(&self) -> AppResult<Option<String>> {
|
||||
self.get_env::<String>("APP_ETCD_CA_CERT_PATH")
|
||||
}
|
||||
|
||||
pub fn etcd_client_cert_path(&self) -> AppResult<Option<String>> {
|
||||
self.get_env::<String>("APP_ETCD_CLIENT_CERT_PATH")
|
||||
}
|
||||
|
||||
pub fn etcd_client_key_path(&self) -> AppResult<Option<String>> {
|
||||
self.get_env::<String>("APP_ETCD_CLIENT_KEY_PATH")
|
||||
}
|
||||
|
||||
pub fn etcd_key_prefix(&self) -> AppResult<String> {
|
||||
self.get_env_or("APP_ETCD_KEY_PREFIX", "/appks/".to_string())
|
||||
}
|
||||
|
||||
pub fn etcd_connect_timeout(&self) -> AppResult<u64> {
|
||||
self.get_env_or("APP_ETCD_CONNECT_TIMEOUT", 5)
|
||||
}
|
||||
|
||||
pub fn etcd_request_timeout(&self) -> AppResult<u64> {
|
||||
self.get_env_or("APP_ETCD_REQUEST_TIMEOUT", 10)
|
||||
}
|
||||
|
||||
pub fn etcd_keep_alive_interval(&self) -> AppResult<u64> {
|
||||
self.get_env_or("APP_ETCD_KEEP_ALIVE_INTERVAL", 10)
|
||||
}
|
||||
|
||||
pub fn etcd_lease_ttl(&self) -> AppResult<u64> {
|
||||
self.get_env_or("APP_ETCD_LEASE_TTL", 15)
|
||||
}
|
||||
|
||||
pub fn etcd_max_retries(&self) -> AppResult<u32> {
|
||||
self.get_env_or("APP_ETCD_MAX_RETRIES", 3)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user