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<<"</a> "<<bb.createtime<<" </p>";
client.val["list"].push(std::move(item));
}
} peer->view("cms/list");
return "";
}
std::string articleshow(std::shared_ptr<httppeer> peer)
{
// step4
httppeer &client = peer->getpeer();
auto articles = orm::cms::Article();
int aid = client.get["id"].to_int(); articles.where("isopen=1").where(" aid=", aid).limit(1).fetch(); client.val["title"] = articles.getTitle();
client.val["content"] = articles.getContent(); peer->view("cms/show");
return "";
}
std::string articleedit(std::shared_ptr<httppeer> peer)
{
// same the show content
httppeer &client = peer->getpeer();
auto articles = orm::cms::Article();
int aid = client.get["id"].to_int(); articles.where("isopen=1").where(" aid=", aid).limit(1).fetch(); client.val["title"] = articles.getTitle();
client.val["content"] = html_encode(articles.getRefContent());
client.val["aid"] = articles.getAid();
peer->view("cms/edit");
return "";
} std::string articleeditpost(std::shared_ptr<httppeer> peer)
{
httppeer &client = peer->getpeer();
std::string title = client.post["title"].to_string();
std::string content = client.post["content"].to_string();
unsigned int aid = client.post["aid"].to_int(); auto articles = orm::cms::Article();
// articles.where("isopen=1").where(" aid=",aid).limit(1).fetch();
// articles.data.aid=aid;
// articles.data.title=title;
// articles.setAid(aid);
articles.setTitle(title);
// articles.setTitle("直接标题");
articles.setContent(content); articles.where(" aid=", aid);
int effectnum = 0;
try
{
effectnum = articles.update("title,content");
}
catch (std::exception &e)
{
client << "<p>" << articles.sqlstring << "</p>";
client << "<p>" << e.what() << "</p>";
return "";
}
if (effectnum > 0)
{ client.goto_url("/cms/list", 3, "内容已经更新");
return "";
}
else
{
client.goto_url("/cms/list", 3, "更新出错(error)");
return "";
} return "";
} std::string articleadd(std::shared_ptr<httppeer> peer)
{
httppeer &client = peer->getpeer();
peer->view("cms/add");
return "";
}
std::string articleaddpost(std::shared_ptr<httppeer> peer)
{
httppeer &client = peer->getpeer();
std::string title = client.post["title"].to_string();
std::string content = client.post["content"].to_string();
unsigned int aid = 0; auto articles = orm::cms::Article(); // articles.data.aid=aid;
// articles.data.title=title;
// articles.setAid(aid);
articles.setIsopen(1);
articles.setCreatetime(date("%Y-%m-%d %X")); // Y-m-d H:i:s
articles.setAddtime(timeid()); // unix timestamp
articles.setAddip(client.client_ip); // client ip
articles.setTitle(title);
// articles.setTitle("直接标题");
articles.setContent(content); int effectnum = 0;
try
{
effectnum = articles.save();
aid = articles.getAid();
client << "<p>新(new)id " << aid << " 或 新(new)id " << effectnum << "</p>";
}
catch (std::exception &e)
{
client << "<p>" << articles.sqlstring << "</p>";
client << "<p>" << e.what() << "</p>";
return "";
}
if (effectnum > 0)
{ client.goto_url("/cms/list", 3, "内容已经添加");
return "";
}
else
{
client.goto_url("/cms/list", 3, "添加出错(error)");
return "";
} return "";
}
std::string articledelete(std::shared_ptr<httppeer> peer)
{
httppeer &client = peer->getpeer();
unsigned int aid = client.get["id"].to_int(); auto articles = orm::cms::Article();
//  可以先查询是否存在或有权限之类
// articles.where("isopen=1").where(" aid=",aid).limit(1).fetch(); int effectnum = 0;
try
{
effectnum = articles.remove(aid);
}
catch (std::exception &e)
{
client << "<p>" << articles.sqlstring << "</p>";
client << "<p>" << e.what() << "</p>";
return "";
}
if (effectnum > 0)
{ client.goto_url("/cms/list", 3, "内容已经删除");
return "";
}
else
{
client.goto_url("/cms/list", 3, "删除出错(error)");
return "";
} return "";
}
}

更看官方controller例子

新款 c++ web framework 支持orm http/2的更多相关文章

  1. Node.js: What is the best "full stack web framework" (with scaffolding, MVC, ORM, etc.) based on Node.js / server-side JavaScript? - Quora

    Node.js: What is the best "full stack web framework" (with scaffolding, MVC, ORM, etc.) ba ...

  2. jQuery Mobile案例,最近用Moon.Web和Moon.Orm做了一套系统

      一.简介 先说说,我们的主题.jQuery Mobile,最近用Moon.Web和Moon.Orm做了一套系统 jQuery Mobile是jQuery 在手机上和平板设备上的版本.jQuery ...

  3. web server && web framework角色区分

    问题 web framework是否包括webserver? 是否可以包括? webserver 和 framework的关系是? https://www.quora.com/What-is-the- ...

  4. [VSTS]让ADO.NET Entity Framework支持Oracle数据库(转载)

    近期由于项目所需不得不研究Oracle数据库,回想上一次用Oracle还是07年的事情,实习时候做华晨宝马的项目简单接触了Oracle.这次的项目需要基于.NET平台,我个人的习惯是能用微软自带的就不 ...

  5. Jena 简介:通过 Jena Semantic Web Framework 在 Jave 应用程序中使用 RDF 模型

    简介: RDF 越来越被认为是表示和处理半结构化数据的一种极好选择.本文中,Web 开发人员 Philip McCarthy 向您展示了如何使用 Jena Semantic Web Toolkit,以 ...

  6. 让ADO.NET Entity Framework支持Oracle数据库

    Oracle最近发布了 Oracle Data Access Component(ODAC)11. 2 Rel 4,其中增加了对 Entity Framework 4.1 和4.2的支持.这让 .NE ...

  7. 通过扩展让ASP.NET Web API支持JSONP

    同源策略(Same Origin Policy)的存在导致了"源"自A的脚本只能操作"同源"页面的DOM,"跨源"操作来源于B的页面将会被拒 ...

  8. 通过扩展让ASP.NET Web API支持W3C的CORS规范

    让ASP.NET Web API支持JSONP和W3C的CORS规范是解决"跨域资源共享"的两种途径,在<通过扩展让ASP.NET Web API支持JSONP>中我们 ...

  9. 让Web API支持Protocol Buffers

    简介 现在我们Web API项目基本上都是使用的Json作为通信的格式,随着移动互联网的兴起,Web API不仅其他系统可以使用,手机端也可以使用,但是手机端也有相对特殊的地方,网络通信除了wifi, ...

  10. 让ASP.NET Web API支持POST纯文本格式(text/plain)的数据

    今天在web api中遇到了这样一个问题,虽然api的参数类型是string,但只能接收post body中json格式的string,不能接收原始string. web api是这样定义的: pub ...

随机推荐

  1. C#-6 运算符和语句

    一 运算符重载 可以重定义或重载 C# 中内置的运算符. 重载运算符是具有特殊名称的函数,是通过关键字 operator 后跟运算符的符号来定义的. public static Box operato ...

  2. POJ2728 Desert King (最小生成树、0/1分数规划)

    显然的0/1分数规划问题,用二分来解决,检验mid,就用prim算法求最小生成树,看总边权是否大等于0即可验证. 1 #include<bits/stdc++.h> 2 using nam ...

  3. Hbase创建表参数说明

    Hbase创建表操作及参数说明 1.创建命名空间 create_namespace 'test' 2.创建user表,列族:info create 'test:user', 'info' 3.查看表结 ...

  4. Linux Block模块之deadline调度算法代码解析

    1 总体说明 Deadline调度器对一个请求的多方面特性进行权衡来进行调度,以期望既能满足块设备扇区的顺序访问又能兼顾到一个请求不会在队列中等待太久导致饿死.Deadline调度器为了兼顾这两个方面 ...

  5. HTML基础知识(1)常用标签的使用 h、p、img、meta、a、iframe...

    文章目录 1.html简介 2.html注释 3.标签的属性 3.1 代码 3.2 测试结果 4.常用的标签 4.1 代码 4.2 测试结果 5.实体 5.1 代码 5.2 测试结果 6.图片引入 6 ...

  6. 记录一次成功反混淆脱壳及抓包激活app全过程

    记录一次成功反混淆脱壳及抓包激活app全过程 前言 ​ 近期接到一个需求,要对公司之前开发的一款app进行脱壳.因为该app是两年前开发的,源代码文件已经丢失,只有加壳后的apk文件,近期要查看其中一 ...

  7. 1、小程序Vant_WebApp组件库的安装步骤和简单使用

    Vant 1.小程序对于npm的支持 目前,小程序当中已经支持使用npm安装的第三方包,通过使用这些第三方包,我们可以提高对小程序开发的效率,但是在小程序当中使用所谓的npm包有如下的三个限制 不能支 ...

  8. 配置文件yaml和ini

    前言 本文主要介绍配置文件yaml和ini的读取. 一.yaml文件 YAML是一个可读性高,易于理解,用来表达数据序列化的格式.语法与python的语法类似.文件后缀  .yaml 下面是yaml文 ...

  9. 浅谈ORM-对象关系映射

    目前.NET(C#)中比较流行的ORM框架: SqlSugar (国内) Dos.ORM (国内) Chloe (国内) StackExchange/Dapper (国外) Entity Framew ...

  10. nrf52——DFU升级USB/UART升级方式详解(基于SDK开发例程)

    摘要:在前面的nrf52--DFU升级OTA升级方式详解(基于SDK开发例程)一文中我测试了基于蓝牙的OTA,本文将开始基于UART和USB(USB_CDC_)进行升级测试. 整体升级流程: 整个过程 ...