前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >新工具介绍:OpenResty Demo 工具链

新工具介绍:OpenResty Demo 工具链

作者头像
糖果
发布2020-11-20 10:43:56
8630
发布2020-11-20 10:43:56
举报
文章被收录于专栏:糖果的实验室糖果的实验室

我刚用 OpenResty Demo 工具链从一个极简单的剧本文件,自动生成了一个短视频,上传到 B 站了:《OpenResty 实现的“你好世界”HTTP示例》。机器自动根据剧本自导、自演、自拍、自配音和自配中英字幕:一条命令搞定。

这里的终端操作全是由我们的 opslang 语言的代码来完成的,包括 vim 的自动化操作。而这里的 opslang 代码也是机器从剧本文档直接生成的。浏览器操作则是由我们的 navlang 语言代码来完成的。当然,navlang 操作复杂 web 应用的能力在这段视频里没机会展示了。等后面更多的视频哈。

这里的终端命令行操作看起来很像人做的,但实际上机器操作时极快,只不过生成视频时为了人能看清楚,故意放慢了而已,实际机器操作黑窗口时在一秒以内就完成了。

作为输入的剧本是长这个样子的哈,我放出来给大家看看:

[V=browser-hello.mp4] Hi, I'm Matthew from OpenResty Inc. In this video, I'll demonstrate how to implement a "hello world" HTTP interface using OpenResty.

First of all, we make sure we are using OpenResty's nginx.

    [delay=0] $ export PATH=/usr/local/openresty/nginx/sbin:$PATH
    $ which nginx

[S] It's usually in this path.

And then we go to the home directory.

    $ cd ~/

Create and switch to a directory named 'hello' for our example.

    $ mkdir hello
    $ cd hello

Create the boilerplate sub-directories for the OpenResty application.

    $ mkdir logs conf
    $ ls

Then let's create a simple nginx.conf file under the 'conf' sub-directory. Here we use vim.

    vim conf/nginx.conf

Let's enable a single nginx worker process for simplicity.

    i [NONL]
    worker_processes 1;
    [NOP]

We enable at most 1024 per-worker connections.

    events {
    worker_connections 1024;
    }
    [NOP]

And here we configure an HTTP server.

    http {
    server {

Listen to the 8080 port with 'reuseport' enabled.

    listen 8080 reuseport;
    [NOP]

Finally we add a root location to this server.

    location / {

We set the default MIME type to text/plain.

    default_type text/plain;

We embed some Lua code to emit a response with the body 'Hello World'.

    content_by_lua_block { ngx.say("Hello World") }
    }
    }
    }

The file is now complete. Let's save it.

    [ESC]
    :w

Quit the vim editor.

    :q
    $

Now let's test if the configuration is correct with the '-t' option.

    $ nginx -p $PWD/ -t

[S] Looking good!

Now let's start this OpenResty application for real.

    $ nginx -p $PWD/

And check if the nginx processes are running.

    $ ps aux|grep nginx|grep -v /tmp/

[S] Nice. They are up. One master and one worker.

We can now send a test HTTP request to this server with the 'curl' command-line utility.

    $ curl 'http://127.0.0.1:8080/'

[S] We're indeed getting the response body 'Hello World'.

[V=browser-hello.mp4] We can also try accessing the / URI in a web browser.

[S] As we can see, it also displays "Hello World" as expected.

[S] If you like this video, please subscribe to our channel. Thank you!

这个输入文件是 .sp 后缀,即英文单词 screenplay 的缩写,表示"剧本“。这个语言的名字叫 screenplay,是一种类似自然语言的小语言。这个剧本里引用的 browser-hello.mp4 视频则是由 navlang 生成的。

从同样的剧本文件,OpenResty Demo 工具链也能自动生成图文并茂的文字版教程,我刚发表在我们的官方博客网站上面了。这是中文版:《使用 OpenResty 实现”你好世界” HTTP 示例》,而这是英文版:《Hello World HTTP Example in OpenResty》。多语言翻译也是机器自动完成的。文中的插图也自动取自 mp4 视频文件。工具链此时生成的是 markdown 文件。

这个 OpenResty Demo 工具链产品也只会提供给我们 OpenResty Inc. 公司的商业客户了哈。我们会继续免费分享工具链生成的更多视频和文章。

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2020-11-17,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 糖果的实验室 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档