maxence-charriere /go-app
A package to build progressive web apps with Go programming language and WebAssembly.
★ 8,984⑂ 406👁 139⑃ 591● 558▤ 129
+0
Daily
8,984
stars
406
forks
139
watchers
591
prs
558
issues
129
releases
README
Go-app is a package for building progressive web apps (PWAs) with Go and WebAssembly (Wasm).
Write your UI in Go using reusable components and a declarative syntax. Handle user interactions in Go and serve your app with the standard net/http package.
Apps built with go-app are SEO-friendly and support offline use. On supported browsers and devices, users can install your app and run it in its own window.
Documentation (built with go-app)
Install
Requires Go 1.26 or newer.
From your project directory, initialize a Go module if you do not already have one. Replace example.com/myapp with your module path:
sh
go mod init example.com/myapp
Add go-app to your project:
sh
go get github.com/maxence-charriere/go-app/v11/pkg/app
Components
Describe your UI with Go functions using go-app's declarative syntax. Each component embeds app.Compo and defines a Render method that returns its UI.
Create a main.go file with the following component, then add the main function from the next section. The component displays a greeting that updates as you type your name:
go
package main
import (
"log"
"net/http"
"github.com/maxence-charriere/go-app/v11/pkg/app"
)
type hello struct {
app.Compo
name string
}
func (h hello) Render() app.UI {
return app.Div().Body(
app.H1().Body(
app.Text("Hello, "),
app.If(h.name != "", func() app.UI {
return app.Text(h.name)
}).Else(func() app.UI {
return app.Text("World!")
}),
),
app.Input().
Type("text").
Value(h.name).
Placeholder("What is your name?").
AutoFocus(true).
OnInput(h.ValueTo(&h.name)),
)
}
Serving the app
Serve your app with Go's standard net/http package. The app.Handler type implements http.Handler and can be used with an existing Go server.
Add this function to main.go to register the component at / and serve the app on port 8000:
go
func main() {
// Register the component.
app.Route("/", func() app.Composer { return &hello{} })
// Start the app in the browser; on the server, continue below.
app.RunWhenOnBrowser()
// Serve the app over HTTP.
http.Handle("/", &app.Handler{
Name: "Hello",
Description: "A Hello World example",
})
if err := http.ListenAndServe(":8000", nil); err != nil {
log.Fatal(err)
}
}
Build and run
From your project directory, build the WebAssembly app and the server, then run the server:
sh
mkdir -p web
GOOS=js GOARCH=wasm go build -o web/app.wasm
go build -o server
./server
Open localhost:8000 in your browser. After changing the code, rebuild both binaries and restart the server.
Getting started
Follow the Getting Started guide to build and run your first app.
Built with go-app
- Murlok: World of Warcraft character builds and guides.
- GoApp Docs: The documentation website, built with go-app.
- liwasc: Network discovery, port scanning, and Wake-on-LAN.
Support the project
If go-app is useful to you, consider sponsoring its development.Top issues
#679Tinygo is just one package away33 comments · 2022-01-09#992OnNav runs before being able to access localstorage states in v10?14 comments · 2024-09-20#689Allow Render() return nil9 comments · 2022-01-20#1024Documentation issue in Components page8 comments · 2025-02-11#1107OnChange fails to update event handler when function is a closure6 comments · 2026-01-28#1010bug: Stale event handlers with Range5 comments · 2025-01-03#1039Better Examples4 comments · 2025-02-26#1029Single HTML deployment4 comments · 2025-02-18
Latest release
v11.1.5 v11.1.5 2026-11-03What's Changed Handle _blank targets case-insensitively by @arbachak in https://github.com/maxence-charriere/go-app/pull/1157 Full Changelog: https://github.com/maxence-charriere/go-app/compare/v11.1.4...v11.1.5