1pub mod notification;
9pub mod cache_plugin;
10pub mod async_task;
11pub mod scheduler;
12pub mod sid_plugin;
13pub mod serial_plugin;
14
15use alun_core::PluginManager;
16use alun_config::AppConfig;
17use tracing::info;
18pub fn create_plugins_from_config(config: &AppConfig) -> PluginManager {
20 let mut mgr = PluginManager::new();
21 let plugins_cfg = &config.plugins;
22
23 for name in &plugins_cfg.enabled {
24 match name.as_str() {
25 "notification" => {
26 let p = notification::NotificationPlugin::from_config(
27 &plugins_cfg.notification,
28 );
29 mgr = mgr.add(p);
30 info!("插件: notification 已注册");
31 }
32 "async-task" => {
33 let p = async_task::AsyncTaskPlugin::new(
34 plugins_cfg.async_task.workers,
35 );
36 mgr = mgr.add(p);
37 info!("插件: async-task 已注册");
38 }
39 "scheduler" => {
40 let p = scheduler::SchedulerPlugin::new();
41 mgr = mgr.add(p);
42 info!("插件: scheduler 已注册");
43 }
44 "cache" => {
45 let p = cache_plugin::CachePlugin::new(&config.app_name, &config.cache, &config.redis);
46 mgr = mgr.add(p);
47 info!("插件: cache 已注册");
48 }
49 "sid" => {
50 let p = sid_plugin::SidPlugin::new();
51 mgr = mgr.add(p);
52 info!("插件: sid 已注册");
53 }
54 "serial" => {
55 let p = serial_plugin::SerialPlugin::with_memory(
56 plugins_cfg.serial.clone(),
57 );
58 mgr = mgr.add(p);
59 info!("插件: serial 已注册(memory 后端)");
60 }
61 _ => {
62 tracing::warn!("未知插件: {},跳过", name);
63 }
64 }
65 }
66
67 mgr
68}