mygo README

The project's README from github.com/egoist/mygo. As one markdown file: README.md.

MyGo

Desktop apps in Go, with a web frontend or a native UI.

Each MyGo window shows one of two kinds of interface, and one app can mix them:

Either way, an app is a single Go binary of a few megabytes, focused on low memory and CPU use.

A window with a web page, whose frontend calls Go:

type Greeter struct{}

// Greet returns a greeting.
func (Greeter) Greet(name string) string { return "Hello, " + name }

func main() {
	mygo.Bind(Greeter{})
	mygo.App.WhenReady(func() {
		mygo.NewWindow(mygo.WindowOptions{Title: "Hello", URL: "/"})
	})
	if err := mygo.App.Run(); err != nil {
		log.Fatal(err)
	}
}
import { Greeter } from "./mygo"; // generated

document.body.textContent = await Greeter.greet("Ada");

A window with native UI, whose view is a Go function of the app's state:

type counter struct{ n int }

func (s *counter) view(c *ui.Context) {
	ui.Column(c).Fill().Center().Gap(12).Children(func() {
		ui.Text(c, fmt.Sprint(s.n)).FontSize(40).Bold()
		if ui.PrimaryButton(c, "Increment").Clicked() {
			s.n++
		}
	})
}

func main() {
	s := &counter{}
	mygo.App.WhenReady(func() {
		mygo.NewWindow(mygo.WindowOptions{
			Title:   "Counter",
			Content: ui.View(s.view),
		})
	})
	if err := mygo.App.Run(); err != nil {
		log.Fatal(err)
	}
}

Getting started

With Go 1.27+ and Bun, create an app with a web frontend:

bunx mygo-cli init my-app      # or: npx mygo-cli init my-app
cd my-app
bun run dev

An app of native UI needs Go alone:

go run github.com/egoist/mygo/cmd/mygo@latest init -template native my-app
cd my-app
go tool mygo dev

Read the documentation.

License

MIT

mygo (egoist/mygo)

Searching Database…

2.4K ·GitHub
这是什么?MyGo 是一个用于构建桌面应用的 Go 工具集:应用既可以把网页前端嵌入操作系统的原生 webview,也可以渲染由 MyGo 自己在 GPU 上绘制的完全原生 UI,而且可以在一个应用中混用两者。
这是一个 webview 套壳,还是真正的原生 UI 工具集?两者都是:窗口可以是运行在操作系统 webview(WKWebView、WebKitGTK 或 WebView2)中的网页,通过生成的 TypeScript 客户端调用 Go 代码;也可以是用 'ui' 包纯 Go 编写的原生 UI,完全不需要 HTML、JS 或 webview。
怎么创建一个新应用?带网页前端的应用用 Go 配合 Bun 生成项目脚手架;纯原生 UI 应用只需要 Go,完全不需要 JS 工具链。
构建带网页前端的应用前需要装好什么?你需要 Go 1.27 或更新版本,外加 Bun;纯原生 UI 应用只需要 Go,因为没有 cgo 依赖,网页部分使用操作系统内置的 webview。
交叉构建需要 cgo 或特定平台的工具链吗?不需要。MyGo 是无 cgo 的纯 Go,因此你可以在一台机器上为 macOS、Windows 和 Linux 构建二进制文件,无需原生工具链。
应用可以发布到哪些操作系统?macOS、Linux 和 Windows;网页前端窗口使用各操作系统自带的 webview(WKWebView、WebKitGTK、WebView2),MyGo 还能生成应用捆绑包、磁盘映像、Windows 安装程序和 Debian 软件包。
原生 UI 工具集开箱自带哪些东西?Flexbox 和网格布局、小部件、支持输入法的文本编辑、虚拟化列表、SVG 图标、动画、读屏器支持,以及无需打开窗口就能测试的视图。
它能为我的应用提供自动更新吗?可以。MyGo 支持带增量更新的签名自动更新和一个类似 Sparkle 的更新窗口,还为分发提供代码签名和公证。
MyGo 应用有多小、多轻量?应用编译为单个几 MB 的 Go 二进制文件;由于是无 cgo 的纯 Go,且原生 UI 完全绕过 webview,它始终保持低内存和低 CPU 占用。
同一个应用里能混用网页窗口和原生 UI 窗口吗?可以。MyGo 的每个窗口要么是网页,要么是原生 UI,一个应用可以组合这两种窗口。
Creator
egoist
Size
59 MB
Stars
2.4K
Age
24d
Commits · 90 Days