folk-plugin-http 0.1.1

HTTP plugin for Folk — accepts connections via hyper and dispatches to PHP workers
Documentation
use anyhow::Result;
use async_trait::async_trait;
use folk_api::{PluginContext, RpcMethodDef, ServerPlugin};
use tracing::info;

use crate::config::HttpConfig;
use crate::server::HttpServer;

pub struct HttpPlugin {
    config: HttpConfig,
}

impl HttpPlugin {
    pub fn new(config: HttpConfig) -> Self {
        Self { config }
    }
}

#[async_trait]
impl ServerPlugin for HttpPlugin {
    fn name(&self) -> &'static str {
        "http"
    }

    async fn run(&self, ctx: PluginContext) -> Result<()> {
        let server = HttpServer::new(self.config.clone(), ctx.executor.clone());
        info!(listen = %self.config.listen, "http plugin listening");
        server.run(ctx.shutdown).await
    }

    fn rpc_methods(&self) -> Vec<RpcMethodDef> {
        vec![RpcMethodDef::new(
            "http.connections",
            "current active connection count",
        )]
    }
}