Drogon是一个基于C++的跨平台HTTP应用程序框架,它支持Linux,也支持macOS、FreeBSD,OpenBSD,HaikuOS,和Windows。项目地址:https://github.com/drogonframework/drogon。
它的主要特点如下:
在Ubuntu22环境下使用docker搭建drogon。
| 代码拉取 | 如已将代码从github clone到了目录/mnt/hgfs/github/下 |
| 构建docker镜像 | root@weisonxs:/mnt/hgfs/github/drogon/docker/ubuntu# ls Dockerfile root@weisonxs:/mnt/hgfs/github/drogon/docker/ubuntu# vi Dockerfile root@weisonxs:/mnt/hgfs/github/drogon/docker/ubuntu# docker build --tag drogon . Sending build context to Docker daemon 2.56kB Step 1/10 : FROM ubuntu:20.04 20.04: Pulling from library/ubuntu |
| 查看生成的镜像 | root@weisonxs:/mnt/hgfs/github/drogon/docker/ubuntu# docker images REPOSITORY TAG IMAGE ID CREATED SIZE drogon latest 84006ea67fa9 11 minutes ago 1.19GB ubuntu 20.04 d5447fc01ae6 5 weeks ago 72.8MB |
| 运行容器 | root@weisonxs:/mnt/hgfs/github/drogon/docker/ubuntu# docker run -idt drogon /bin/bash 84607cd8e44ddc84a9f5449e562cac137fc1b0e24b53b3aa7bcd0f6566e33c2b |
| 进入容器 | root@weisonxs:/mnt/hgfs/github/drogon/docker/ubuntu# docker attach 84607cd8e44ddc84a9f5449e562cac137fc1b0e24b53b3aa7bcd root@84607cd8e44d:/install/drogon# ls0f6566e33c2b |
| 构建安装drogon | root@84607cd8e44d:/install/drogon# ./build.sh |
| 运行实例 | build目录下examples |
| 注 | 虚拟机配置成了静态ip,所用的dns是通用的,所以下载github的东西可能解析地址不了——先切换回dhcp,下载完再切回来 |
| cmake | cmake配置 |
| docker | docker配置文件 |
| drogon_ctl | drogon命令工具 |
| examples | 实例 |
| lib | drogon库,有关drogon的框架实现源文件和头文件都在这里 |
| nosql_lib | 非关系型数据库 |
| ormlib | ORM(对象关系映射)库 |
| third_party | 第三方组件 |
| trantor | C++高性能网络库 |
| build.sh | 构建drogon脚本 |
| CmakeLists.txt | 生成整个项目的cmake文件 |
| conanfile.txt | 项目依赖项列表 |
| 基类(抽象类) | 派生的类(实现类) | 功能 | 继承的类 |
| HttpAppFramework | HttpAppFrameworkImpl | 整个程序框架的入口 | NonCopyable |
| HttpClientImpl | Http客户,与服务器建立持久的连接 | NonCopyable | |
| HttpController | 无 | HTTP控制器的反射基类模板 | DrObject<T>, HttpControllerBase |
| HttpSimpleController | 无 | 简单HTTP控制器的反射基类模板 | DrObject<T>, HttpControllerBase |
| 辅助类 | 功能 |
| trantor/ | |
| EventLoop | 运行在某个特定线程上的一个事件循环 |
| InetAddress | sockaddr_in的封装器。是一个POD接口类 |
| Date | 时间点类 |
| Logger | 实现日志功能 |
| CacheMap | 缓存映射工具类 |
| Multipart.h | (单个请求中)传输多个部分数据处理(上传文件或二进制数据) |
| Cookie | cookie类 |
| Session | session类 |
| IOThreadStorage | 线程存储处理工具类 |
| UploadFile | 这个类表示一个上传文件,它将通过multipart/form-data格式传输到服务器 |
| Dbclient | |
| utils/ | |
| Utilities.h | 各种工具类头文件 |
| plugins/ | |
| Plugin | 插件的反射基类 |
| SecureSSLRedirector | 将所有非HTTPS请求重定向到HTTPS请求的插件(除了ssl_redirect_exempt中所定义的URL) |
| AccessLogger | 打印所有请求到日志的插件 |
| RealIpResolver | 从HTTP请求中解析客户真实IP的插件 |
| 管理类 | 功能 |
| StaticFileRouter | 静态文件路由器 |
| HttpControllersRouter | Http控制器路由器 |
| HttpSimpleControllersRouter | Http简单控制器路由器 |
| WebsocketControllersRouter | Websocket控制器路由器 |
| ListenerManager | 监听管理器 |
| PluginsManager | 插件管理器 |
| DbClientManager | 数据库管理器 |
| RedisClientManager | Redis客户端管理器 |