kwsc98 / fusen-rs

Fusen-rs is a lightweight, high-performance microservice framework based on Tokio's asynchronous threads, compatible with Dubbo and SpringCloud, supporting service registration and discovery through protocol support, and can implement WebService by exposing HTTP interfaces.
Apache License 2.0
223 stars 12 forks source link

对于fusen_server 标注的trait,对外提供Http Url上会带上当前服务的名字作为路径前缀,希望在Url中不出现这个服务名 #24

Closed xtoshii closed 1 month ago

xtoshii commented 1 month ago

跑了下示例

#[fusen_server(id = "org.apache.dubbo.springboot.demo.DemoService")]
impl DemoService for DemoServiceImpl {
    async fn sayHello(&self, req: String) -> FusenResult<String> {
        info!("res : {:?}", req);
        Ok("Hello ".to_owned() + &req)
    }
    #[asset(path="/sayHelloV2-http",method = POST)]
    async fn sayHelloV2(&self, req: ReqDto) -> FusenResult<ResDto> {
        let _span = info_span!("sayHelloV2-http").entered();
        info!("开始处理 sayHelloV2-http");
        info!("接收消息 : {:?}", req);
        let _span2 = info_span!("get_user_info_by_db").entered();
        info!("get_user_info_by_db : selet * from user where id = $1");
        drop(_span2);
        Ok(ResDto::default().str("Hello ".to_owned() + req.get_str() + " V2"))
    }
    #[asset(path="/divide",method = GET)]
    async fn divideV2(&self, a: i32, b: i32) -> FusenResult<String> {
        info!("res : a={:?},b={:?}", a, b);
        Ok((a + b).to_string())
    }
}

对于这样一个Http服务实现来说,完整的请求路径就是 http://127.0.0.1:8082/DemoService/sayHelloV2-http

希望DemoService 在路径不出现,或者fusen_server 提供一个path参数做当前trait接口实现的统一配置

xtoshii commented 1 month ago

我改了下fusen_server 和 fusen_trait,会移除 parent_path, 如果可以的话,希望能提个pr

kwsc98 commented 1 month ago

实际上#[asset]也可以直接标注在impl上,来替换root路径,这样就会暴露 http://127.0.0.1:8082/demo/sayHelloV2-http

#[fusen_server(id = "org.apache.dubbo.springboot.demo.DemoService")]
#[asset(path="/demo",method = POST)]
impl DemoService for DemoServiceImpl {
    async fn sayHello(&self, req: String) -> FusenResult<String> {
        info!("res : {:?}", req);
        Ok("Hello ".to_owned() + &req)
    }
    #[asset(path="/sayHelloV2-http",method = POST)]
    async fn sayHelloV2(&self, req: ReqDto) -> FusenResult<ResDto> {
        let _span = info_span!("sayHelloV2-http").entered();
        info!("开始处理 sayHelloV2-http");
        info!("接收消息 : {:?}", req);
        let _span2 = info_span!("get_user_info_by_db").entered();
        info!("get_user_info_by_db : selet * from user where id = $1");
        drop(_span2);
        Ok(ResDto::default().str("Hello ".to_owned() + req.get_str() + " V2"))
    }
    #[asset(path="/divide",method = GET)]
    async fn divideV2(&self, a: i32, b: i32) -> FusenResult<String> {
        info!("res : a={:?},b={:?}", a, b);
        Ok((a + b).to_string())
    }
}
kwsc98 commented 1 month ago

非常感谢可以关注这个项目,并且想为此做贡献,本项目还处于初期,欢迎一起来建设此项目!!!

kwsc98 commented 1 month ago

如果不想使用二级目录的话,可以目前这么使用,不过确实不优雅,你可以看一下有没有更好的实现方式 #[asset(path="",method = POST)]