folk_plugin_http/
plugin.rs1use anyhow::Result;
2use async_trait::async_trait;
3use folk_api::{PluginContext, RpcMethodDef, ServerPlugin};
4use tracing::info;
5
6use crate::config::HttpConfig;
7use crate::server::HttpServer;
8
9pub struct HttpPlugin {
10 config: HttpConfig,
11}
12
13impl HttpPlugin {
14 pub fn new(config: HttpConfig) -> Self {
15 Self { config }
16 }
17}
18
19#[async_trait]
20impl ServerPlugin for HttpPlugin {
21 fn name(&self) -> &'static str {
22 "http"
23 }
24
25 async fn run(&self, ctx: PluginContext) -> Result<()> {
26 let server = HttpServer::new(self.config.clone(), ctx.executor.clone());
27 info!(listen = %self.config.listen, "http plugin listening");
28 server.run(ctx.shutdown).await
29 }
30
31 fn rpc_methods(&self) -> Vec<RpcMethodDef> {
32 vec![RpcMethodDef::new(
33 "http.connections",
34 "current active connection count",
35 )]
36 }
37}