When building modules developers frequently have to specify different config values in their local dev or test environments vs when module is loaded on production servers.
static ENV_CONFIG: OnceCell<EnvConfig> = OnceCell::new();
fn init(_ctx: &Context, args: &[ValkeyString]) -> Status {
// if env arg passed, use it
let env_name = match args.get(0) {
Some(tmp) => tmp.to_string(),
None => "".to_string(),
};
let _ = ENV_CONFIG.set(EnvConfig::new(env_name.as_str()));
Status::Ok
}
#[derive(Debug, Deserialize)]
pub(crate) struct EnvConfig {
pub(crate) foo: String,
pub(crate) bar: i32,
}
impl EnvConfig {
pub(crate) fn new(env: &str) -> Self {
let env_config = match env {
"dev" => EnvConfig {
foo: "dev_foo".to_string(),
bar: 1
},
_ => EnvConfig {
// default to prod
foo: "prod_value".to_string(),
bar: 2
},
};
env_config
}
}
When building modules developers frequently have to specify different config values in their local dev or test environments vs when module is loaded on production servers.
Pass env like this
MODULE LOAD /path/here/libmodule1.dylib dev