3 releases
0.0.4 | Feb 28, 2024 |
---|---|
0.0.3 | Feb 19, 2024 |
0.0.2 | Feb 16, 2024 |
#1735 in Network programming
53 downloads per month
Used in kokoro
32KB
686 lines
Kokoro is a Rust-based meta-framework that prioritizes memory safety, performance, and stability to empower the creation of highly decoupled applications.
Advantages
- Memory Safety ๐ฆ: Built with Rust's guarantees of memory safety, Kokoro eliminates the need for manual side-effect management.
- High Performance โก๏ธ: Designed for efficiency, Kokoro ensures rapid response times and exceptional performance.
- Stable & Reliable ๐๏ธ: Continuously optimized, Kokoro aims to provide stable support for production environments in the future.
- Dynamic Plugins ๐: Supports dynamic plugins, including WASM and dynamic linking libraries, for functional expansion.
- Hot Module Replacement ๐: Simplifies the hot update process based on dynamic plugins, making it easy to understand and implement.
- Flexibility ๐: Highly decoupled by nature, Kokoro allows for easy extension or modification. Modular, loosely coupled, hot-updatable, and distributed - all possible with Kokoro.
Getting Started
ๅฎ็ฝ todo
Demo
use kokoro::{dynamic_plugin::toml::toml, prelude::*};
use kokoro_plugin_tiny_http_event::{http::Response, *};
fn main() -> Result<()> {
// Create a context for the channel.
let ctx = channel_ctx();
// Initialize a new PluginFinder to search for plugins in the "./plugin" directory.
let pf = PluginFinder::new("./plugin");
// Find the "kokoro_plugin_tiny_http" plugin.
let plugin = pf.find("kokoro_plugin_tiny_http");
// Define the configuration for the plugin using TOML format.
let config = toml! {
host = "0.0.0.0" // The host address where the server will listen.
port = 1145 // The port number for the server.
};
// Load the plugin dynamically with the specified configuration.
ctx.plugin_dynamic(plugin, Some(config.into()))?;
// Subscribe to the 'hello' event.
ctx.subscribe(hello);
// Run the context synchronously.
ctx.run_sync();
// Return Ok if everything executes successfully.
Ok(())
}
// Define a new Path named 'Hello' targeting the "/hello" endpoint.
path!(Hello, "/hello");
// Define the 'hello' function to handle requests to the 'Hello' path.
fn hello(req: PathQuery<Hello>) {
// Check if there is a request and take ownership of it.
if let Some(req) = req.take() {
// Respond to the request with a "Hello World!" message.
req.respond(Response::from_string("Hello World!")).unwrap();
}
}
This code sets up a simple HTTP server that responds with โHello World!โ when the โ/helloโ path is accessed. It uses the tiny_http plugin for handling HTTP events.
Star History
todo list
-
kokoro-default-impl
-
kokoro-plugin-impl
-
kokoro-thread-impl
-
kokoro-service-impl
-
-
kokoro-dynamic-plugin-impl
- plugin config api
-
loader
for dynamically and schematically loading plugins. -
logger
for uniform output logging of plugins. -
k-onfig
is used to hint configuration schema. -
Satori (EventType only)
for instant messaging or chatbots
Dependencies
~2.4โ8.5MB
~52K SLoC