Hunt framework 2.0.0 發(fā)布,簡單且高性能的 Web 服務(wù)框架

HuntLabs 很高興的趕在大年三十之前宣布:通過 Hunt framework 1.0.0 后面的一些版本( 1.1.x / 1.5.x)迭代終于迎來 2.0.0,這個版本對我們來說很重要,對整個框架的完整性和易用性再一次得到了提升。

Hunt framework 是一個使用 Dlang 語言開發(fā)的全棧 web 框架,易用性和完整性都貼近于 Laravel / Django / Spring boot 等主流框架的設(shè)計,優(yōu)勢主要體現(xiàn)在部署方面,不需要搭建運(yùn)行環(huán)境就可開啟 web 服務(wù)。而且 D 語言自身是一個性能極高的編譯型語言,我們可以基于 hunt framework 非常簡單的開發(fā)出高性能的 web 服務(wù)。

版本主要更新特性

  1. 更多 HTTP 標(biāo)準(zhǔn) API 進(jìn)行支持
  2. 完成 HTTP 2.0 支持,包含 H2 和 H2C
  3. I/O 模塊性能改進(jìn)
  4. Collie 庫使用新的 hunt-http 庫進(jìn)行替代
  5. 數(shù)據(jù)庫相關(guān)模塊的增強(qiáng),包含分頁器和連接池修復(fù)
  6. 新的模板引擎解析器,更好的兼容 twig 和 jinja2 語法
  7. 表單校驗(yàn)器的實(shí)現(xiàn)
  8. 面包屑模塊設(shè)計與實(shí)現(xiàn)
  9. I18N 多語言模塊完整的實(shí)現(xiàn)
  10. 基于 STOMP 協(xié)議的 WebSocket 模塊實(shí)現(xiàn)
  11. 移植了 java 的大部分容器對象方便開發(fā)者使用
  12. 加強(qiáng)了單元測試模塊和更多的示例代碼

依賴的庫進(jìn)行升級

Name Version
hunt 1.0.0
hunt-cache 0.2.2
hunt-database 1.1.0
hunt-entity 2.2.0
hunt-http 0.1.1
hunt-imf 0.0.4
hunt-net 0.1.0
hunt-security 0.0.6
hunt-sql 1.0.5
hunt-stomp 0.0.3
hunt-trace 0.1.7
hunt-validation 0.0.2
boringssl 0.0.1
dredis 0.0.9
libmemcached 1.1.1
openssl 1.1.6+1.0.1g
protobuf 0.4.0
rocksdb 0.0.7

I18N 多語言示例代碼

定義語言包在 resources/translations/en-us/messages.ini

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

在配置文件設(shè)置默認(rèn)語言 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"));
            });
    }

頁面的面包屑進(jìn)行賦值

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 方面一些改進(jìn)

HTTP client

HTTP server

WebSocket client

WebSocket server

HTTP2

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

文件上傳支持改進(jìn)

       @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;
        }

表單驗(yàn)證示例代碼

定義表單對象

   module app.form.LoginForm;

    import hunt;

    class LoginForm : Form
    {
        mixin MakeForm;

        @Length(6,20)
        string username;

        @Length(8,16)
        string password;
    }

驗(yàn)證

   @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 簡化改進(jìn)

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

數(shù)據(jù)庫方面改進(jìn)

加強(qiáng) Entity & EQL 的分頁支持:

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

EQL 增強(qiáng)

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

Validation

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

內(nèi)置的鏈路跟蹤初步支持

New modules used to tracing the requests in microservice architectures.

I/O 性能測試結(jié)果

The core I/O library is refactored, and is called Hunt.

Benchmark

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 官網(wǎng)

https://www.huntlabs.net/

Github 代碼倉庫

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

Gitee 碼云代碼倉庫

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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容