Hunt framework 2.0.0 发布,简单且高性能的 Web 服务框架

栏目: 软件资讯 · 发布时间: 5年前

内容简介:HuntLabs 很高兴的赶在大年三十之前宣布:通过 Hunt framework 1.0.0 后面的一些版本( 1.1.x / 1.5.x)迭代终于迎来 2.0.0,这个版本对我们来说很重要,对整个框架的完整性和易用性再一次得到了提升。 Hunt frame...

HuntLabs 很高兴的赶在大年三十之前宣布:通过 Hunt framework 1.0.0 后面的一些版本( 1.1.x / 1.5.x)迭代终于迎来 2.0.0,这个版本对我们来说很重要,对整个框架的完整性和易用性再一次得到了提升。

Hunt framework 是一个使用 Dlang 语言开发的全栈 web 框架,易用性和完整性都贴近于 Laravel / Django / Spring boot 等主流框架的设计,优势主要体现在部署方面,不需要搭建运行环境就可开启 web 服务。而且 D 语言自身是一个性能极高的编译型语言,我们可以基于 hunt framework 非常简单的开发出高性能的 web 服务。

版本主要更新特性

  • 更多 HTTP 标准 API 进行支持

  • 完成 HTTP 2.0 支持,包含 H2 和 H2C

  • I/O 模块性能改进

  • Collie 库使用新的 hunt-http 库进行替代

  • 数据库相关模块的增强,包含分页器和连接池修复

  • 新的模板引擎解析器,更好的兼容 twig 和 jinja2 语法

  • 表单校验器的实现

  • 面包屑模块设计与实现

  • I18N 多语言模块完整的实现

  • 基于 STOMP 协议的 WebSocket 模块实现

  • 移植了 java 的大部分容器对象方便开发者使用

  • 加强了单元测试模块和更多的示例代码

依赖的库进行升级

NameVersion
hunt1.0.0
hunt-cache0.2.2
hunt-database1.1.0
hunt-entity2.2.0
hunt-http0.1.1
hunt-imf0.0.4
hunt-net0.1.0
hunt-security0.0.6
hunt-sql1.0.5
hunt-stomp0.0.3
hunt-trace0.1.7
hunt-validation0.0.2
boringssl0.0.1
dredis0.0.9
libmemcached1.1.1
openssl1.1.6+1.0.1g
protobuf0.4.0
rocksdb0.0.7

I18N 多语言示例代码

定义语言包在 resources/translations/en-us/messages.ini

WELCOME=Welcome to the world of hunt framework.
VERSION_TITLE=Hunt framework version %s

在配置文件设置默认语言 config/application.conf

hunt.application.defaultLanguage = en-us
hunt.application.languages = zh-cn,en-us

在模板中使用语言词条

<title>{{ trans("VERSION_TITLE", huntVersion) }}</title>

在控制器中使用语言词条

string s = trans("VERSION_TITLE", "2.0.0");

面包屑使用

初始化面包屑配置

app.onBreadcrumbsInitializing((BreadcrumbsManager breadcrumbs) {
        breadcrumbs.register("home", (Breadcrumbs trail, Object[] params...) {
            trail.push("Home", "/home");
        });

        breadcrumbs.register("index.show", (Breadcrumbs trail, Object[] params...) {
            trail.parent("home");
            trail.push("About", url("index.show"));
        });
}

页面的面包屑进行赋值

view.assign("breadcrumbs", breadcrumbsManager.generate("home"));

视图文件代码

    {% if breadcrumbs.defined and breadcrumbs.length>0 %}
    <div class="row">
        <div class="col">
            <ol class="breadcrumb">
                {% for item in breadcrumbs %}
                    {% if item.link and not loop.last %}
                        <li class="breadcrumb-item"><a href="{{ item.link }}">{{ item.title }}</a></li>
                    {% else %}
                        <li class="breadcrumb-item active">{{ item.title }}</li>
                    {% endif %}
                {% endfor %}
            </ol>
        </div>
    </div>
    {% endif %}

HTTP 方面一些改进

  1. HTTP client

  2. HTTP server

  3. WebSocket client

  4. WebSocket server

  5. HTTP2

See: https://github.com/huntlabs/hunt-http/tree/master/examples

文件上传支持改进

    @Action
    string upload()
    {
        string message;

        if (request.hasFile("file1"))
        {
            auto file = request.file("file1");

            if (file.isValid())
            {
                // File save path: file.path()
                // Origin name: file.originalName()
                // File extension: file.extension()
                // File mimetype: file.mimeType()

                if (file.store("uploads/myfile.zip"))
                {
                    message = "upload is successed";
                }
                else
                {

                    message = "save as error";
                }
            }
            else
            {
                message = "file is not valid";
            }
        }
        else
        {
            message = "not get this file";
        }

        return message;
    }

表单验证示例代码

定义表单对象

module app.form.LoginForm;

import hunt;

class LoginForm : Form
{
    mixin MakeForm;
     
    @Length(6,20)
    string username;
    
    @Length(8,16)
    string password;
}

验证

@Action
string login(LoginForm loginForm)
{
    string message;
    auto result = loginForm.valid();

    // TODO
    if(!result.isValid())
    {
       message =  "Valid error message : " ~ result.messages();
    }
    else
    {
        message = "OK";
    }

    return message;
}

文件资源 Response 简化改进

	@Action
    Response download()
    {
        return new FileResponse("/tmp/orders-20190122.zip");
    }

数据库方面改进

加强 Entity & EQL 的分页支持:

https://github.com/huntlabs/hunt-entity/wiki/Pagination

EQL 增强

https://github.com/huntlabs/hunt-entity/wiki/EQL

Validation

https://github.com/huntlabs/hunt-entity/wiki/Validation

内置的链路跟踪初步支持

New modules used to tracing the requests in microservice architectures.

I/O 性能测试结果

The core I/O library is refactored, and is called Hunt.
Hunt framework 2.0.0 发布,简单且高性能的 Web 服务框架

See: https://github.com/huntlabs/hunt-minihttp

更多示例代码

hunt-skeleton: https://github.com/huntlabs/hunt-skeleton
hunt-examples: https://github.com/huntlabs/hunt-examples
hunt-minihttp: https://github.com/huntlabs/hunt-minihttp
hunt-http: https://github.com/huntlabs/hunt-http/tree/master/examples

HuntLabs 官网

https://www.huntlabs.net/

Github 代码仓库

https://github.com/huntlabs/hunt-framework

Gitee 码云代码仓库

https://gitee.com/huntlabs/hunt-framework


以上所述就是小编给大家介绍的《Hunt framework 2.0.0 发布,简单且高性能的 Web 服务框架》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

明解C语言(第3版)

明解C语言(第3版)

[日] 柴田望洋 / 管杰、罗勇、杜晓静 / 人民邮电出版社 / 2015-11-1 / 79.00元

本书是日本的C语言经典教材,自出版以来不断重印、修订,被誉为“C语言圣经”。 本书图文并茂,示例丰富,第3版从190段代码和164幅图表增加至205段代码和220幅图表,对C语言的基础知识进行了彻底剖析,内容涉及数组、函数、指针、文件操作等。对于C语言语法以及一些难以理解的概念,均以精心绘制的示意图,清晰、通俗地进行讲解。原著在日本广受欢迎,始终位于网上书店C语言著作排行榜首位。一起来看看 《明解C语言(第3版)》 这本书的介绍吧!

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具