GitHub - murlokswarm/app: Package to build GUI apps with Go, HTML and CSS.
source link: https://github.com/murlokswarm/app
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
app: a Go package to build GUI
Table of Contents
Install
# Get package.
go get -u -v github.com/murlokswarm/app/...
Hello world
# Go to your go package. cd $GOPATH/src/github.com/USERNAME/hello # Install the required frameworks and generate the app structure. goapp mac init
// main.go func main() { app.Import(&Hello{}) app.Run(&mac.Driver{ OnRun: func() { newWindow() }, OnReopen: func(hasVisibleWindow bool) { if !hasVisibleWindow { newWindow() } }, }) } func newWindow() { app.NewWindow(app.WindowConfig{ Title: "hello world", TitlebarHidden: true, Width: 1280, Height: 768, BackgroundColor: "#21252b", URL: "/Hello", }) } type Hello struct { Name string } func (h *Hello) Render() string { return ` <div class="Hello"> <h1> Hello {{if .Name}} {{.Name}} {{else}} world {{end}}! </h1> <input value="{{.Name}}" placeholder="Say something..." onchange="Name" autofocus> </div> ` }
# Run the app.
goapp mac run
How it works?
app.Run starts the app. It takes an app.Driver as argument. Here we use the MacOS driver implementation. See other drivers.
When creating the window, we set the DefaultURL
to our Hello component
struct name: /Hello
.
It will load the Hello
component when the window is displayed.
Components are structs that implement the app.Compo interface.
Render method returns a string that contains HTML5. It can be templated following Go standard template syntax:
HTML events like onchange
are mapped to the targetted component
field or method.
Here, onchange
is mapped to the field Name
.
Additionally, CSS files can be dropped in PACKAGEPATH/resources/css/
directory.
All .css files within that directory will be included.
See the full example.
Drivers
A driver contains specific code that allows the app package to work on multiple platforms.
Other drivers will come in the future.
Documentation
Examples
From package:
From community:
- grocid/mistlur - use v1
- grocid/passdesktop - use v1
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK