设为首页 加入收藏

TOP

新款 c++ web framework 支持orm http/2(一)
2023-07-23 13:36:03 】 浏览:77
Tags:新款 web framework 支持 orm http/2

c++ web framework很少,

随着c++ 热度升温,c++ 在人工智能 自然语言处理 加快应用。

最近一款国产 c++ web framework 问世

写业务速度跟脚步语言一样速度

  1. 自带json内置支持

  2. 支持多域名网站

  3. 支持多域名ssl 服务端

  4. 支持http1.1、http2协议

  5. 支持websocket服务端,

  6. 框架自带websocket推送,支持定时推送到webscoket客户端

  7. 支持同步httpclient get post

  8. 框架自带ORM,使用链接池方式,目前支持mysql

  9. 框架自带线程池,和用户代码运行的线程池

  10. 框架使用asio自带的协程

  11. 框架特色是I/O 使用协程池 运行使用线程池

  12. 框架支持普通文件gzip br

  13. 框架解析URL和POST,解析结果类似PHP GET POST方式获取内容

  14. 集成sendmail

  15. 生成二维码(qrcode),需要gd、qrencode库

 

目前支持mac linux

具体可以看官方github

https://github.com/hggq/paozhu

 

 

 

主要是写业务代码优雅,方便 CURD例子

 

#include "orm.h"
#include <chrono>
#include <thread>
#include "md5.h"
#include "func.h"
#include "httppeer.h"
#include "testcurd.h"
namespace http
{

   std::string articlelogin(std::shared_ptr<httppeer> peer)
   {
      // step1  show login page
      peer->view("login/login");
      return "";
   }
   std::string articleloginpost(std::shared_ptr<httppeer> peer)
   {
      // step2
      // get login/login post field
      httppeer &client = peer->getpeer();
      std::string username = client.post["username"].to_string();
      std::string password = client.post["password"].to_string();

      auto users = orm::cms::User();
      std::string md5string;
 
      try
      {
         md5string = md5(password);
         users.where("name=", username).whereAnd("password=", md5string).limit(1).fetch();
         // view orm create sql
         // client<<"<p>"<<users.sqlstring<<"</p>";
         if (users.getUserid() > 0)
         {
            // save session,other page get  int userid= client.session["userid"].to_int();
            client.session["userid"] = users.getUserid();
            client.save_session();
            client.goto_url("/cms/list");
            return "";
         }
         else
         {
            client.goto_url("/cms/login",3,"用户名或密码错误!");
            return "";
         }
      }
      catch (std::exception &e)
      {
         client << "<p>" << e.what() << "</p>";
         return "";
      }

      return "";
   }
   std::string articlelist(std::shared_ptr<httppeer> peer)
   {
      // step3 content list
      httppeer &client = peer->getpeer();
      int userid = client.session["userid"].to_int();
      if (userid == 0)
      {
         // client.goto_url("/cms/login");
         client.val["msg"] = "<a href=\"/cms/login\">Please login </a>";
      }

      auto articles = orm::cms::Article();

      int page = client.get["page"].to_int();
      if (page < 0)
      {
         page = 0;
      }
      page = page * 20;
      articles.where("isopen=1").order(" aid desc ").limit(page, 20).fetch();
      // 也可以直接返回OBJ_VALUE 对象; 不过正常业务会要处理下结果集
      // You can also return the OBJ_VALUE object directly; but normal business process will need to process the result set
      client.val["list"].set_array();
      if (articles.size() > 0)
      {
         for (auto &bb : articles)
         {

            OBJ_ARRAY item;
            item["aid"] = bb.aid;
            item["title"] = bb.title;
            item["createtime"] = bb.createtime;
            item["summary"] = bb.summary;
            // client<<"<p><a href=\"/cms/show?id="<<bb.aid<<"\">"<<bb.title<&l
首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇1分钟理清楚C++类模板和模板类区别 下一篇<三>线程间互斥-mutex互斥..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目