From 5bec01b9df40f60be8367c75e2fc622d55bd18ff Mon Sep 17 00:00:00 2001 From: chatlanin Date: Wed, 10 Jul 2024 09:32:45 +0300 Subject: [PATCH] move impl from register_function and register_inspector to registration --- src/trs/trs.hpp | 16 +++++++--------- tests/main.cpp | 19 +++++++++---------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/trs/trs.hpp b/src/trs/trs.hpp index 41781ce..42c1e81 100644 --- a/src/trs/trs.hpp +++ b/src/trs/trs.hpp @@ -29,21 +29,19 @@ namespace trs set_idle_interval(0, 1'000'000); set_payload_max_length(1024 * 1024 * 512); // 512MB set_CORS(); + set_post(); database::instance().set_connection(app_connection, log_connection); } - template - void register_function(Key func_name, Function func) { m_function_manager.register_function(func_name, func); } - - template - void register_inspector(Key func_name, Function func) { m_inspector.register_function(func_name, func); } + template + void registration(std::string func_name, Function insp, Function func) + { + m_inspector.register_function(func_name, insp); + m_function_manager.register_function(func_name, func); + } void run() { - // HERE - // может в init перенести ??? - set_post(); - try { hack::log(" ")("server listen:", var::HOST, var::PORT); diff --git a/tests/main.cpp b/tests/main.cpp index 1dfc6a4..ea52e70 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -5,13 +5,6 @@ namespace worckspaces { - inline void provider(trs::transaction& tr) - { - hack::log()("provider", tr.m_data.m_payload); - tr.m_data.m_result["status"] = "ok"; - tr.m_data.m_result["result"] = "super ok"; - } - inline void inspector(trs::transaction& tr) { if (tr.m_data.m_payload.size() != 0) @@ -23,14 +16,20 @@ namespace worckspaces throw ex; } } + + inline void provider(trs::transaction& tr) + { + hack::log()("provider", tr.m_data.m_payload); + tr.m_data.m_result["status"] = "ok"; + tr.m_data.m_result["result"] = "super ok"; + } } auto main(int argc, char* args[]) -> int { trs::http app; - app.register_function("healthcheck", worckspaces::provider); - app.register_inspector("healthcheck", worckspaces::inspector); - app.init("app_connection", "log_connection"); + + app.registration("healthcheck", worckspaces::inspector, worckspaces::provider); app.run(); }