go-pwa

module
v0.0.0-...-4a4e7c0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2024 License: MIT

README

go-pwa

Notice: this is a fork of maxence-charriere/go-app.

go-pwa is a package for building progressive web apps (PWA) with the Go programming language (Golang) and WebAssembly (Wasm).

Shaping a UI is done by using a declarative syntax that creates and compose HTML elements only by using the Go programing language.

It uses Go HTTP standard model.

An app created with go-pwa can out of the box runs in its own window, supports offline mode, and is SEO friendly.

Install

go-pwa requirements:

go mod init
go get -u github.com/carmel/go-pwa

Declarative syntax

go-pwa uses a declarative syntax so you can write reusable component-based UI elements just by using the Go programming language.

Here is a Hello World component that takes an input and displays its value in its title:

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 != "",
				app.Text(h.name),
			).Else(
				app.Text("World!"),
			),
		),
		app.P().Body(
			app.Input().
				Type("text").
				Value(h.name).
				Placeholder("What is your name?").
				AutoFocus(true).
				OnChange(h.ValueTo(&h.name)),
		),
	)
}

Standard HTTP

Apps created with go-pwa complies with Go standard HTTP package interfaces.

func main() {
	// Components routing:
	app.Route("/", &hello{})
	app.Route("/hello", &hello{})
	app.RunWhenOnBrowser()

	// HTTP routing:
	http.Handle("/", &app.Handler{
		Name:        "Hello",
		Description: "An Hello World! example",
	})

	if err := http.ListenAndServe(":8000", nil); err != nil {
		log.Fatal(err)
	}
}

Sample

Directories

Path Synopsis
docs
src
pkg
analytics
Package analytics provides functions to send analytics to analytics stores such as Google Analytics.
Package analytics provides functions to send analytics to analytics stores such as Google Analytics.
app
Package app is a package to build progressive web apps (PWA) with Go programming language and WebAssembly.
Package app is a package to build progressive web apps (PWA) with Go programming language and WebAssembly.
cli
Package cli is a package to build CLI programs.
Package cli is a package to build CLI programs.
logs
Package logs implements functions to manipulate logs.
Package logs implements functions to manipulate logs.
ui
Package ui provides a set of components to organize an application layout.
Package ui provides a set of components to organize an application layout.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL