From 86f5e710497ff2d1e1c6b88c54a1390695275ee7 Mon Sep 17 00:00:00 2001 From: xx Date: Tue, 28 May 2024 11:44:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/net/http_router.h | 9 ++++++--- src/db/mysql.cpp | 2 +- src/net/http_cdn.cpp | 2 +- src/net/http_router.cpp | 5 +++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/net/http_router.h b/include/net/http_router.h index 484d5e7..17214ee 100644 --- a/include/net/http_router.h +++ b/include/net/http_router.h @@ -36,7 +36,7 @@ namespace ylib // 请求类型 network::http::method method; // 回调函数 - std::function callback; + std::function callback; // 控制器。为控制器则启动下面两个属性 bool controller; // 创建控制器类指针 @@ -49,6 +49,8 @@ namespace ylib // LUA虚拟机初始化回调 std::function lua_init_state; #endif + // 附加数据 + void* extra = nullptr; }; /************************************************************************* * class:路由中专服务 @@ -94,9 +96,10 @@ namespace ylib * 同一地址不允许订阅两次 ******************************************************************/ void subscribe( - const std::string& path, + const std::string& path, network::http::method method, - std::function callback + std::function callback, + void* extra = nullptr ); #define SUBSCRIBE(ROUTER,CONTROLLER,FUNCTION,PATH,METHOD) ROUTER->subscribe([]()->void*{return new CONTROLLER;},(ylib::network::http::HTTP_CTR_FUNCTION)&CONTROLLER::FUNCTION,PATH,METHOD) diff --git a/src/db/mysql.cpp b/src/db/mysql.cpp index 7d32a48..f25f45a 100644 --- a/src/db/mysql.cpp +++ b/src/db/mysql.cpp @@ -456,7 +456,7 @@ std::string ylib::mysql::result::field_name(uint32 index) std::string ylib::mysql::result::field_type(uint32 index) { - return strutils::change_case(RESULT_SET->getMetaData()->getColumnTypeName(index)); + return strutils::change_case(RESULT_SET->getMetaData()->getColumnTypeName(index),false); } std::string ylib::mysql::result::field_type(const std::string& name) diff --git a/src/net/http_cdn.cpp b/src/net/http_cdn.cpp index aed3b17..82e5868 100644 --- a/src/net/http_cdn.cpp +++ b/src/net/http_cdn.cpp @@ -81,7 +81,7 @@ bool network::http::cdn::start(const cdn_config& config){ else { std::cout<<"CDN:Node start"<router()->subscribe("/info",network::http::GET,[&](network::http::request* request,network::http::response* response){ + website()->router()->subscribe("/info",network::http::GET,[&](network::http::request* request,network::http::response* response,void* extra){ ylib::json rep; std::string value_key; if(request->header("key",value_key) == false || m_cdn_node_key != value_key){ diff --git a/src/net/http_router.cpp b/src/net/http_router.cpp index 96da277..068344e 100644 --- a/src/net/http_router.cpp +++ b/src/net/http_router.cpp @@ -74,7 +74,7 @@ network::http::interceptor* network::http::router::interceptor(){ return m_interceptor; } -void network::http::router::subscribe(const std::string &path, network::http::method method, std::function callback) +void network::http::router::subscribe(const std::string &path, network::http::method method, std::function callback, void* extra) { #if HTTP_ROUTER_PRINT == 1 ylib::log->info("[subscribe][func] express:"+path+" method:"+method_to_string(method),"router"); @@ -84,6 +84,7 @@ void network::http::router::subscribe(const std::string &path, network::http::me svie->method = method; svie->express = std::regex(path.c_str()); svie->callback = callback; + svie->extra = extra; m_subscribe.append(svie); } void network::http::router::subscribe( @@ -197,7 +198,7 @@ void ylib::network::http::router::__thread_callback(reqpack* rp) //普通回调 if (sub->callback != nullptr) { - sub->callback(rp->request(), rp->response()); + sub->callback(rp->request(), rp->response(),sub->extra); } else {