PaoZhu C++ Web Framework 内置HTTP/2 ORM 可以完全开发Web生态,提供注解功能。
C++ 注解机制更加简单- //@urlpath(admin_islogin,admin/add_article)
复制代码 一句话可以把一个函数变成注解函数,admin_islogin是拦截函数,访问admin/add_article之前执行认证,如果没有认证,不能执行注解函数。
详细代码,在controller/src目录下创建文件article- //@urlpath(admin_islogin,admin/add_article)
- std::string admin_add_article(std::shared_ptr<httppeer> peer)
- {
- httppeer &client = peer->get_peer();
- client<<"Hello World!";
- return "";
- }
复制代码 同步模式- //@urlpath(null,queries)
- asio::awaitable<std::string> techempowerqueries(std::shared_ptr<httppeer> peer)
- {
- peer->type("application/json; charset=UTF-8");
- peer->set_header("Date", get_gmttime());
-
- unsigned int get_num = peer->get["queries"].to_int();
- if (get_num == 0)
- {
- get_num = 1;
- }
- else if (get_num > 500)
- {
- get_num = 500;
- }
- auto myworld = orm::World();
- myworld.record.reserve(get_num);
- myworld.lock_conn();
- for (unsigned int i = 0; i < get_num; i++)
- {
- myworld.wheresql.clear();
- unsigned int rd_num = rand_range(1, 10000);
- myworld.where("id", rd_num);
- co_await myworld.async_fetch_append();
- }
- myworld.unlock_conn();
- peer->output = myworld.to_json();
- co_return "";
- }
复制代码 他们都是方便利用了注解功能做控制器。
更多入门内容可以访问官方入门文档。
https://hggq.github.io/paozhudocs/documentation.html
Paozhu C++ Web框架 官方github库
https://github.com/hggq/paozhu
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |