• Stars
    star
    7,899
  • Rank 4,506 (Top 0.1 %)
  • Language
    Go
  • License
    MIT License
  • Created over 5 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build cross-platform modern desktop apps in Go + HTML5

Lorca

Build Status GoDoc Go Report Card

Lorca

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
<-ui.Done()

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.

More Repositories

1

jsmn

Jsmn is a world fastest JSON parser/tokenizer. This is the official repo replacing the old one at Bitbucket
C
3,504
star
2

awfice

The world smallest office suite
HTML
3,440
star
3

fenster

The most minimal cross-platform GUI library
C++
495
star
4

tray

Cross-platform, super tiny C99 implementation of a system tray icon with a popup menu.
C
465
star
5

partcl

ParTcl - a micro Tcl implementation
C
459
star
6

metric

Minimal metrics for Go (counter/gauge/histogram). No dependencies. Compatible with expvar. Web UI included.
Go
352
star
7

luash

Tiny lua module to write shell scripts with lua (inspired by Python's sh module)
Lua
302
star
8

pt

Protothreads (coroutines) in C99. Highly portable, but work best in low-end embedded systems.
C
262
star
9

o

Tiny and simple React clone
JavaScript
241
star
10

lua-promises

A+ promises in Lua
Lua
214
star
11

log

Ultimately minimal (yet very convenient) logger for Android and Java
Java
158
star
12

tojvm

A toy JVM in Go
Go
155
star
13

bfapi

Resilient, scalable Brainf*ck, in the spirit of modern systems design
Go
144
star
14

webview-python

Python bindings to webview
Objective-C
143
star
15

hid

Simple HID driver for Go (pure golang, no dependencies, no cgo)
Go
119
star
16

nokia-composer

Nokia Composer in 512 bytes
HTML
118
star
17

expr

Fast and lightweight math expression evaluator in C99
C
115
star
18

zs

Absolutely minimal static site generator in Go (powers https://zserge.com)
Go
90
star
19

tinysh

Tiny UNIX shell, de-obfuscated, modernized, and "rewritten in Rust".
C
85
star
20

nanonn

A nano-framework for neural networks
Rust
83
star
21

dotfiles

git clone --bare https://github.com/zserge/dotfiles $HOME/.dotfiles && git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME checkout
Vim Script
79
star
22

lc3-forth

Post-Apocalyptic Computing: bootstrapping Forth environment for LC-3 CPU
C
75
star
23

1bitr

Minimalistic text-based 1-bit music tracker
C
71
star
24

carnatus

A tiny chess engine in Go (sunfish port)
Go
64
star
25

odetoj

Rewrite of Arthur Whitney's one-page J interpreter in Rust
Rust
60
star
26

headline

Ascetic RSS reader in JavaScript, no server required
JavaScript
57
star
27

buckbone

A simple android project generator for the Buck build system
Shell
52
star
28

glob-grep

A little experiment: compare the languages aimed to replace C
Zig
51
star
29

q

Tiny and simple VueJS clone
JavaScript
46
star
30

beep

Cross-platform beep() function
C
42
star
31

slide

An attempt to implement Trikita Slide for desktop
C++
39
star
32

figma-simplify-path

Figma plugin to simplify vector paths
JavaScript
24
star
33

mucks

A tiny terminal session manager for Tmux, Screen and DVTM
Shell
20
star
34

anvil-kotlin-demos

Minimal tutorial/demos for Anvil+Kotlin
Kotlin
18
star
35

zserge.github.io

My static site
HTML
14
star
36

kv

An ultimately minimal persistent key-value store + LRU cache
Go
12
star
37

jsmn.lua

The world fastest JSON parser ported to Lua
Lua
11
star
38

yu

Yu is a tee-like tool, but with rotation feature like logrotate
C
10
star
39

aint

Code for the "AI or AIN'T" blog posts
Go
9
star
40

mdns

Very pragmatic mDNS implementation in Go
Go
8
star
41

kveer

A tiny in-memory key-value storage in Go with optional persistence (atomic backup file, or append-only)
Go
7
star
42

bf

Well, everyone has to write a brainf*ck interpreter at some point
C
7
star
43

toy-java-agent

Toy Java agent
Java
6
star
44

covered

Trello Cover Card Generator
JavaScript
6
star
45

bsoz

One of the most minimal MOS6502 and retro computer emulators!
C
6
star
46

atomicwriter

Atomic file writes in Go (using a unique temporary file and atomic rename)
Go
5
star
47

lex

A library for writing lexers in Go
Go
4
star
48

textizer

Minimal android widgets in Scheme
Java
4
star
49

chess

JavaScript
4
star
50

ping

An ultimately minimal social network, messaging, pub/sub and home automation app
4
star
51

photo

Minimalistic private photo booth
HTML
3
star
52

incr

incr.it backend
JavaScript
3
star
53

one-click-hugo-cms

CSS
2
star
54

grafana-zero

Python
2
star
55

gif

Simple GIF recorder
HTML
2
star
56

protoc-gen-micro

Protobuf code generation for micro
Go
2
star
57

scaffold

Templates for quick project start
Java
1
star
58

r

Something that rhymes. Or not.
1
star
59

tabs

🎼 A tiny CLI tool to render tabs for music instruments (🎹🎷🎺🎸πŸͺ•πŸͺˆ and many others!)
C
1
star