资源正则表达式导致恐慌

问题描述

  1. 这段代码试图用一个用 rust 编写的服务替换一个已经在生产中运行的服务,用 Java 编写。
  2. 此服务将作为 redis 集群的 sidecar 代理,公开 api rest。它需要保持与当前 api 的兼容性。

路线是:

"/api/keys/{path:*}" 

在path中我们可以放redis的key的名称,可以包含以下任意格式:

/api/keys/users/41728391
/api/keys/users/1000/followers
/api/keys/users/{1234}/data

这是我的尝试

 HttpServer::new(move || App::new()
        .data(redis_config)
        .service(
            web::resource("/set/{path:*}").route(web::put().to(set_key))
        ) ).bind(("127.0.0.1",8080))?
        .run()
        .await

我也这样试过:

#[get("/set/{path:*}")]...

但在两种情况下我会收到此错误

  .service(web::resource("/set/{path:*}").route(web::put().to(path_regex)))
   |                                                                         ^^^^^^^^^^ the trait `Factory<_,_,_>` is not implemented for `path_regex`



thread 'thread 'actix-rt:worker:1actix-rt:worker:0' panicked at '' panicked at 'Wrong path pattern: "/set/{path:*}" regex parse error:
    ^/set/(?P<path>*)$
                   ^
error: repetition operator missing expressionWrong path pattern: "/set/{path:*}" regex parse error:
    ^/set/(?P<path>*)$
               ^

我已阅读https://actix.rs/actix-web/actix_web/web/fn.resource.html

我的代码是:https://github.com/rogeriob2br/enge-sidecar-redis

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)