ballerina 学习一 基本项目安装试用
ballerina介绍
1. 安装
直接下载对应操作系统的二进制文件即可,同时官方也提供了linux 操作系统对应的各种发行包(deb, rpm)
参考地址:
https://ballerina.io/downloads/
2. 基本代码
// Packages contain functions, annotations and connectors.
// This package is referenced by ‘http’ namespace in the code
// body.
import ballerina/http;
import ballerina/io;
// A service is a network-accessible API. This service
// is accessible at '/hello', and bound to a the listener on
// port 9090. `http:Service`is a connector in the `http`
// package.
service<http:Service> hello bind { port: 9090 } {
// A resource is an invokable API method.
// Accessible at '/hello/sayHello’.
// 'caller' is the client invoking this resource.
sayHello (endpoint caller, http:Request request) {
// Create object to carry data back to caller.
http:Response response = new;
// Objects have function calls.
response.setTextPayload("Hello Ballerina!\n");
// Send a response back to caller.
// Errors are ignored with '_'.
// ‘->’ is a synchronous network-bound call.
_ = caller -> respond(response);
}
}
备注:第一眼看上去,代码还是很清晰的,也比较简单,比较完整的代码可以参考
https://github.com/ballerina-platform/ballerina-examples
3. 运行
ballerina run app.bal
备注: 很简单,就是可能启动会稍微有点慢
4. 访问
上面的代码已经说明了访问方式
http://hostip:port(9090)/hello/sayHello
结果:
HTTP/1.1 200 OK
content-type: text/plain
content-length: 17
server: ballerina/0.970.1
date: Mon, 14 May 2018 10:01:38 +0800
Hello Ballerina!
5. 总结
从官方介绍的特性来说还是很不错的,同时开发团队也提供了主流编辑器的可用插件,vscode idead 。。。
开发也比较简单,总的来说还是比较看好,具体的性能测试,目前暂时没有看到相关的结果,比较期待。
6. 参考资料
https://github.com/rongfengliang/ballerina-basic-demo
https://github.com/ballerina-platform/ballerina-examples
https://ballerina.io/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2015-05-14 js 动态 activex 组件
2014-05-14 IE6/IE7下:inline-block解决方案
2014-05-14 IEPNGFix 解决IE6支持PNG透明问题
2014-05-14 Oracle:Decode在时间范围中的使用
2014-05-14 使用 dl 设计的简单的登陆界面 (为了记录)