3 Star 8 Fork 0

金鑫 / Weasel

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSD-3-Clause

Weasel介绍

Weasel是一个可以使用Lua语言进行Http接口开发的Web服务器,目前只在CentOS 7.8中进行测试。

使用的其他开源库

1.lua         https://www.lua.org/
2.json4lua    https://github.com/craigmj/json4lua
3.mysql c api https://dev.mysql.com/doc/c-api/5.7/en/

目录介绍

├── 3rdparty                    #第三方开源库
│   ├── json4lua                #json4lua,用于lua table结构与json数据的相互转换
│   └── lua53                   #lua
├── app                         #app目录
│   └── TemplateApp             #模板app
├── docs                        #文档目录
│   ├── json4lua                #json4lua的文档
│   └── lua53                   #lua5.3的文档
├── src                         #项目源码目录
│   ├── http                    #http协议封装处理等实现
│   ├── main.cpp                #程序入口
│   ├── net                     #核心网络通讯部分实现
│   └── tools                   #一些工具功能实现
├── bin                         #编译后程序目录
├── CMakeLists.txt              #CMake工程文件
└── LICENSE                     #许可

编译

  • 编译前需确认mysql-devel是否安装,可以使用 yum install mysql-devel 命令进行安装。
1.    mkdir build
2.    cd build
3.    cmake ..
4.    make 
程序会生成在bin目录中

App介绍

对于Weasel来说,一个App就是一个项目,每个App都是独立的。

目录

├── app                         #app目录
│   └── TemplateApp             #app模板工程
│       ├── 3rdparty            #第三方库
│       │   └── json.lua        #json4lua
│       ├── models              #模型实体文件夹,用于之后的ORM管理
│       │   └── test_model.lua  测试用实体
│       ├── settings.lua        #配置文件
│       ├── urls.lua            #路由文件
│       └── views               #视图目录
│           └── test.lua        #测试用视图

常用命令

创建app

Weasel createapp App名称
Weasel createapp test1

启动app

Weasel runapp App名称
Weasel runapp test1

停止app

Weasel stopapp App名称
Weasel stopapp test1

路由

--路由文件为 urls.lua

--引用test视图
local test = require('views.test')

urlpatterns = {
    --设置test视图路由为/api/test/
    ['/api/test/'] = test
}

视图

视图基础结构

--视图文件存储在views文件夹下
--views/test.lua

--定义test视图
local test = {
    --对应get方法
    get = function(request)
        local res = response(404, 'error')
        return res
    end,
    --对应post方法
    post = function(request)
        local res = response()
        res.head = {['asdf'] = 'adsf'}
        res.content = '3245345345345'
        return res
    end
}
--返回视图
return test

request结构

  • request.url
  • request.body
  • request.type
  • request.head['Content-Type']
  • request.param['sectioncode']

response结构

  • response.status
  • response.status_info
  • response.content
  • response.head['Content-Type']
  • response.cookie['sectioncode']

接口权限

BSD 3-Clause License Copyright (c) 2021, KimCarlton All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

简介

Weasel是一个可以使用Lua语言进行Http接口开发的Web服务器。 展开 收起
C++ 等 3 种语言
BSD-3-Clause
取消

发行版 (1)

全部

贡献者

全部

近期动态

加载更多
不能加载更多了
C++
1
https://gitee.com/KimCarlton/Weasel.git
git@gitee.com:KimCarlton/Weasel.git
KimCarlton
Weasel
Weasel
main

搜索帮助