pub mod host_proxy;
pub mod logging;
pub mod runtime;
pub mod trace;
use std::sync::OnceLock;
pub use host_proxy::HostProxy;
pub use runtime::{host, run, PluginApp};
pub use trace::{instrument, span_for, with_trace};
static PLUGIN_ID: OnceLock<String> = OnceLock::new();
pub(crate) fn set_plugin_id(plugin_id: &str) {
let _ = PLUGIN_ID.set(plugin_id.to_string());
}
pub fn init() {
if let Ok(id) = std::env::var("ZEROLAUNCH_PLUGIN_ID") {
set_plugin_id(&id);
}
}
pub fn t_key(key: &str) -> String {
let plugin_id = PLUGIN_ID
.get()
.expect("t_key 必须在插件运行时初始化后调用(run() 之后)");
format!("plugin.{plugin_id}.{key}")
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn t_key_prefixes_current_plugin_id() {
set_plugin_id("com.example.hello-world");
assert_eq!(t_key("greeting"), "plugin.com.example.hello-world.greeting");
assert_eq!(t_key("sayHello"), "plugin.com.example.hello-world.sayHello");
}
}