go html极小ui,lorca: 一个很小的库,用于在Go中构建现代HTML5桌面应用程序。它使用Chrome浏览器作为UI层。与Electron不同,它不会将Chrome捆绑到应用程序包中,而是...

Lorca是一个小型的Go库,用于构建基于HTML5的桌面应用程序,利用已安装的Chrome浏览器作为UI层。它提供纯Go接口,简单API,应用体积小,结合了HTML/CSS的美观和Go的高性能。Lorca支持与JavaScript交互,异步流程,本地服务器或数据URL加载Web UI,还支持头less模式测试和多窗口。不过,它要求已安装Chrome/Chromium 70+,并有一些设计上的限制,如无法控制窗口样式和菜单。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Lorca

CI%20Pipeline

lorca?status.svg

lorca

d0441353abbeba570617558d66470392.png

A very small library to build modern HTML5 desktop apps in Go. It uses Chrome

browser as a UI layer. Unlike Electron it doesn't bundle Chrome into the app

package, but rather reuses the one that is already installed. Lorca

establishes a connection to the browser window and allows calling Go code

from the UI and manipulating UI from Go in a seamless manner.

Features

Pure Go library (no cgo) with a very simple API

Small application size (normally 5-10MB)

Best of both worlds - the whole power of HTML/CSS to make your UI look

good, combined with Go performance and ease of development

Expose Go functions/methods and call them from JavaScript

Call arbitrary JavaScript code from Go

Asynchronous flow between UI and main app in both languages (async/await and Goroutines)

Supports loading web UI from the local web server or via data URL

Supports testing your app with the UI in the headless mode

Supports multiple app windows

Supports packaging and branding (e.g. custom app icons). Packaging for all

three OS can be done on a single machine using GOOS and GOARCH variables.

Also, limitations by design:

Requires Chrome/Chromium >= 70 to be installed.

No control over the Chrome window yet (e.g. you can't remove border, make it

transparent, control position or size).

No window menu (tray menus and native OS dialogs are still possible via

3rd-party libraries)

If you want to have more control of the browser window - consider using

webview library with a similar API, so

migration would be smooth.

Example

ui, _ := lorca.New("", "", 480, 320)

defer ui.Close()

// Bind Go function to be available in JS. Go function may be long-running and

// blocking - in JS it's represented with a Promise.

ui.Bind("add", func(a, b int) int { return a + b })

// Call JS function from Go. Functions may be asynchronous, i.e. return promises

n := ui.Eval(`Math.random()`).Float()

fmt.Println(n)

// Call JS that calls Go and so on and so on...

m := ui.Eval(`add(2, 3)`).Int()

fmt.Println(m)

// Wait for the browser window to be closed

22a9941096e111ed66d7098ec05a607f.gif

Also, see examples for more details about binding functions and packaging binaries.

Hello World

Here are the steps to run the hello world example.

cd examples/counter

go get

go run ./

How it works

Under the hood Lorca uses Chrome DevTools Protocol to instrument on a Chrome instance. First Lorca tries to locate your installed Chrome, starts a remote debugging instance binding to an ephemeral port and reads from stderr for the actual WebSocket endpoint. Then Lorca opens a new client connection to the WebSocket server, and instruments Chrome by sending JSON messages of Chrome DevTools Protocol methods via WebSocket. JavaScript functions are evaluated in Chrome, while Go functions actually run in Go runtime and returned values are sent to Chrome.

What's in a name?

There is kind of a legend, that before his execution Garcia Lorca have seen a

sunrise over the heads of the soldiers and he said "And yet, the sun rises...".

Probably it was the beginning of a poem. (J. Brodsky)

Lorca is an anagram of Carlo, a

project with a similar goal for Node.js.

License

Code is distributed under MIT license, feel free to use it in your proprietary

projects as well.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值