Skip to content

Commit

Permalink
feat(plugin): add first trait for interface
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 18, 2021
1 parent 309198e commit dbb6274
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions plugin_interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]


[dependencies.core_model]
path = "../core_model"

13 changes: 13 additions & 0 deletions plugin_interface/src/interface.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use core_model::CocoConfig;

pub trait PluginInterface {
/// name of plugins
/// should start with `coco.`, such as `coco.swagger`
fn name(&self) -> &'static str;
/// event for load plugin
fn on_plugin_load(&self) {}
/// event of unload plugin
fn on_plugin_unload(&self) {}
/// execute plugin
fn execute(&self, config: CocoConfig);
}
3 changes: 2 additions & 1 deletion plugin_interface/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod plugin_interface;
pub use interface::PluginInterface;
pub mod interface;
1 change: 0 additions & 1 deletion plugin_interface/src/plugin_interface.rs

This file was deleted.

6 changes: 6 additions & 0 deletions plugins/coco_swagger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]

[dependencies.core_model]
path = "../../core_model"

[dependencies.plugin_interface]
path = "../../plugin_interface"
18 changes: 18 additions & 0 deletions plugins/coco_swagger/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use core_model::CocoConfig;
use plugin_interface::PluginInterface;

pub struct CocoSwagger {}

impl PluginInterface for CocoSwagger {
fn name(&self) -> &'static str {
"coco.swagger"
}

fn on_plugin_load(&self) {}

fn on_plugin_unload(&self) {}

fn execute(&self, config: CocoConfig) {
println!("{:?}", config);
}
}
3 changes: 0 additions & 3 deletions plugins/coco_swagger/src/main.rs

This file was deleted.

0 comments on commit dbb6274

Please sign in to comment.