webtool

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: BSD-3-Clause Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package webtool packages a Glutter app for the web (SPEC §23.1): it builds the program for js/wasm, writes the directory that a static web server can serve (index.html, wasm_exec.js, app.wasm and app.wasm.gz), and serves such a directory with the right types and with the gzip file for a browser that accepts it. cmd/glutter-web is its command line, and internal/webtest uses it to run apps in browsers.

Flutter: no counterpart (flutter build web, flutter run -d web-server).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CachingHandler

func CachingHandler(dir string) http.Handler

CachingHandler is Handler for a build whose files the browser may keep for a while, as a site that is deployed would let it: the measurement of the start with app.wasm in the browser's cache (SPEC §15) needs it. A new build is not seen until the time is up.

Flutter: no counterpart

func Handler

func Handler(dir string) http.Handler

Handler serves the directory of a web build (SPEC §23.1): index.html for "/", every file with its type (app.wasm as application/wasm, which instantiateStreaming needs), and, to a browser that accepts gzip, app.wasm.gz in place of app.wasm with Content-Encoding gzip. Nothing outside the directory is reachable, and nothing is cached by the browser, so a new build is the one that loads.

Flutter: no counterpart

func IndexHTML

func IndexHTML(p Page) ([]byte, error)

IndexHTML makes the index.html of the app: the viewport meta tag, globalThis.glutterConfig, wasm_exec.js and the loader (SPEC §23.1). A message inside <noscript> is for a browser without JavaScript.

Flutter: no counterpart (flutter build web's index.html)

func LoaderJS

func LoaderJS() string

LoaderJS is the JavaScript of the loader that index.html contains.

Flutter: no counterpart (flutter_bootstrap.js)

Types

type BuildOptions

type BuildOptions struct {
	// Package is the main package to build, as `go build` takes it: "./examples/counter".
	Package string
	// OutDir is the directory to write the build to; it is created.
	OutDir string
	// Release builds with -tags glutter_release and -ldflags=-s -w (SPEC §23.1).
	Release bool
	// Dir is the directory to run the go command in, which Package is relative to. The
	// default is the current directory.
	Dir string
	// HostElement is the CSS selector of the element the view fills; empty fills the page.
	HostElement string
	// Body is HTML for the body of index.html, before the loader: the host element when
	// HostElement is set. Empty by default.
	Body string
	// Title is the title of index.html; the base name of Package when empty.
	Title string
	// Env is added to the environment of the go command.
	Env []string
}

BuildOptions are the parameters of Build.

Flutter: no counterpart

type BuildResult

type BuildResult struct {
	// Dir is the directory of the build.
	Dir string
	// WasmSize and GzipSize are the sizes of app.wasm and app.wasm.gz in bytes.
	WasmSize, GzipSize int64
}

BuildResult says what Build wrote, all in OutDir.

Flutter: no counterpart

func Build

func Build(ctx context.Context, o BuildOptions) (*BuildResult, error)

Build builds the package for js/wasm with the standard Go toolchain (TinyGo is not supported, D18) and writes the directory that any static web server can serve (SPEC §23.1): index.html, wasm_exec.js (copied from $(go env GOROOT)/lib/wasm, which must match the Go that builds), app.wasm and app.wasm.gz. It fails with WebBuildFailed when the go command fails (its output is in the error's metadata) and with WebWriteFailed when a file cannot be written.

Flutter: no counterpart (flutter build web)

type Page

type Page struct {
	// Title is the title of the page until the app sets its own.
	Title string
	// HostElement is the CSS selector for globalThis.glutterConfig.hostElement; empty
	// leaves the view to fill the page (SPEC §23.2).
	HostElement string
	// Body is HTML put into the body before the loader: the host element of a page that
	// embeds the app in an element of its own (SPEC §23.2).
	Body string
}

Page describes the index.html of an app.

Flutter: no counterpart

Jump to

Keyboard shortcuts

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