fix: config empty values unset, drop adapter from_vars
This commit is contained in:
@@ -15,40 +15,23 @@ pub struct NatsConfig {
|
||||
|
||||
impl NatsConfig {
|
||||
pub fn from_config(config: &::config::NatsConfig) -> anyhow::Result<Self> {
|
||||
Self::from_vars(
|
||||
config.url.as_deref(),
|
||||
Some(&config.mode),
|
||||
Some(&config.subject_prefix),
|
||||
Some(&config.stream_name),
|
||||
Some(&config.consumer_name),
|
||||
)
|
||||
}
|
||||
let url = config
|
||||
.url
|
||||
.clone()
|
||||
.ok_or_else(|| anyhow::anyhow!("NATS_URL is not set"))?;
|
||||
|
||||
pub(crate) fn from_vars(
|
||||
url: Option<&str>,
|
||||
mode: Option<&str>,
|
||||
subject_prefix: Option<&str>,
|
||||
stream_name: Option<&str>,
|
||||
consumer_name: Option<&str>,
|
||||
) -> anyhow::Result<Self> {
|
||||
let url = url.ok_or_else(|| anyhow::anyhow!("NATS_URL is not set"))?;
|
||||
|
||||
let mode = match mode.unwrap_or("jetstream") {
|
||||
let mode = match config.mode.as_str() {
|
||||
"core" => NatsMode::Core,
|
||||
"jetstream" => NatsMode::JetStream,
|
||||
other => anyhow::bail!("unknown NATS_MODE: {other}"),
|
||||
};
|
||||
|
||||
let subject_prefix = subject_prefix.unwrap_or("movies-diary.events").to_string();
|
||||
let stream_name = stream_name.unwrap_or("MOVIES_DIARY_EVENTS").to_string();
|
||||
let consumer_name = consumer_name.unwrap_or("worker").to_string();
|
||||
|
||||
Ok(Self {
|
||||
url: url.to_string(),
|
||||
url,
|
||||
mode,
|
||||
subject_prefix,
|
||||
stream_name,
|
||||
consumer_name,
|
||||
subject_prefix: config.subject_prefix.clone(),
|
||||
stream_name: config.stream_name.clone(),
|
||||
consumer_name: config.consumer_name.clone(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user