guodongxiaren edited a comment on issue #1528:
URL: https://github.com/apache/incubator-brpc/issues/1528#issuecomment-903257185


   `cntl->http_request().method()` 
判断是哪个HTTP的method,然后调用你不同的函数(把不同的method的处理逻辑封装成单独的函数)就行吧。
   
   
   接口这样定义:
   ```proto
   service MyService {
     rpc item(HttpRequest) returns (HttpResponse);
   };
   ```
   
   你的Service类:
   ```cpp
   class MyServiceImpl : public MyService {
   public:
       MyServiceImpl() {};
       virtual ~MyServiceImpl() {};
       void item(google::protobuf::RpcController* cntl_base,
                  const HttpRequest*,
                  HttpResponse*,
                  google::protobuf::Closure* done) {
           brpc::ClosureGuard done_guard(done);
           brpc::Controller* cntl =
               static_cast<brpc::Controller*>(cntl_base);
   
           auto method = cntl->http_request().method();
           if ( method == HTTP_METHOD_POST) {
                ....
           } else if (method == HTTP_METHOD_DELETE) {
               ....
           } else if (method == HTTP_METHOD_PUT) {
               ....
           } else if (method == HTTP_METHOD_GET) {
              ....
           }
       }
   ````
   
   如果你想路径名是`/item`  而不是`/MyService/item`
   
   那么brpc也支持:
   ```cpp
       MyServiceImpl svc;
       if (server.AddService(&svc,
                             brpc::SERVER_DOESNT_OWN_SERVICE,
                             "/item   => item") != 0) {
           LOG(ERROR) << "Fail to add queue_svc";
           return -1;
       }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to