Handler and deployment
Configure app.Handler, serve static files, prerender pages, ship updates, publish a static site and run it locally.
app.Handler
is the server half of a WebGo app. It renders each routed page to HTML, and serves the manifest, the service worker, the JavaScript support files and everything under
/web/
. This page lists its fields, then follows an app from its static files through prerendering, updates and installation to a static site on GitHub Pages.
Stylesheets,
WebDir
and
Build
are covered under
Handler and Build
. The smallest working server is in
Getting Started
.
§1 The handler
Every field is optional.
Handler
has unexported fields, so a composite literal must name the fields it sets, and the handler must be used through a pointer. A typical production handler:
handler
:=
&
app
.
Handler
{
Name
:
"Notes"
,
ShortName
:
"Notes"
,
Title
:
"Notes"
,
Description
:
"A notebook that works offline"
,
Author
:
"Ana Silva"
,
Keywords
:
[
]
string
{
"notes"
,
"offline"
}
,
Image
:
"/web/card.png"
,
Domain
:
"notes.example.com"
,
Icon
:
app
.
Icon
{
Default
:
"/web/icon-192.png"
,
Large
:
"/web/icon-512.png"
,
SVG
:
"/web/icon.svg"
,
Maskable
:
"/web/icon-maskable.png"
,
}
,
BackgroundColor
:
"#ffffff"
,
ThemeColor
:
"#1a1a1a"
,
Styles
:
[
]
style
.
Style
{
style
.
Static
(
"/web/main.css"
)
}
,
Scripts
:
[
]
string
{
"/web/chart.js defer"
}
,
Fonts
:
[
]
string
{
"/web/inter.woff2"
}
,
}
http
.
Handle
(
"/"
,
handler
)
The handler fills in its defaults on the first request, or when
app.GenerateStaticWebsite
runs it. Changing a field after that has no effect.
Page metadata
Name
string
ShortName
string
Title
string
Description
string
Author
string
Keywords
[
]
string
Image
string
Domain
string
Lang
string
LoadingLabel
string
-
NameandShortNamego into the manifest. Each defaults to the other. IfName,ShortNameandTitleare all empty,Nameis"App PWA". -
Title,Description,Author,KeywordsandImageare the defaults for every page's<title>,<meta>and Open Graph tags. A component overrides them per page throughctx.Page(), under Prerendering and SEO . The keywords tag is written only whenKeywordsis not empty. -
Domainmakes social URLs absolute:og:url,og:image,twitter:imageand the canonical link becomehttps://<Domain><path>. With noDomainthey becomehttps://<path>, which no crawler can use, so set it whenever pages are shared. -
Langis thelangattribute of<html>. It defaults to"en". -
LoadingLabelis the text under the icon whileapp.wasmdownloads.{progress}is replaced with the percentage. It defaults to"{progress}%", and the server writes it with0.
Icons and colours
Icon
Icon
BackgroundColor
string
ThemeColor
string
type
Icon
struct
{
Default
string
Large
string
SVG
string
Maskable
string
}
-
Defaultis a 192×192 PNG. It is the loading image and a manifest icon. If it is empty,Default,Largeand an emptySVGbecome go-app's logo. -
Largeis a 512×512 PNG for the manifest. An emptyLargeis left out of it. -
SVGis the favicon (<link rel="icon">) and the manifest's scalable icon. When it is empty, the favicon isDefaultand the manifest has no SVG icon. -
Maskableis a 512×512 PNG with a safe zone for adaptive icons. It is also theapple-touch-icon. It falls back toDefault. -
BackgroundColorandThemeColorgo into the manifest, andThemeColoralso into<meta name="theme-color">. Both default to#2d2c2c.
Head resources
Styles
[
]
Stylesheet
Scripts
[
]
string
Imports
[
]
Module
Fonts
[
]
string
Preconnect
[
]
string
CacheableResources
[
]
string
RawHeaders
[
]
string
-
Stylesis covered under Handler and Build . -
Scriptsbecome<script src>tags afterapp.js, in order. An entry may end withdefer,async,crossoriginorcrossorigin=<value>after a space:"/web/chart.js defer". -
Importsare ES modules loaded through one importmap beforeapp.wasmstarts, under Scripts . -
Fontsbecome<link rel="preload" as="font">tags whosetypeisfont/plus the file extension. -
Preconnectentries become<link rel="preconnect">tags, one per origin. -
CacheableResourcesare extra files the service worker stores for offline use. Icons, fonts, stylesheets, scripts andapp.wasmare stored already. -
RawHeadersare written as they are, unescaped, at the end of<head>. Use them for third-party snippets such as analytics tags.
Document
HTML
func
(
)
HTMLHtml
Body
func
(
)
HTMLBody
These build the
<html>
and
<body>
elements. They default to
app.Html
and
app.Body
. Use them to add attributes; the handler sets
lang
and the children itself:
handler
:=
&
app
.
Handler
{
Name
:
"Notes"
,
HTML
:
func
(
)
app
.
HTMLHtml
{
return
app
.
Html
(
)
.
DataSet
(
"theme"
,
"dark"
)
}
,
}
Runtime
StartURL
string
Env
map
[
string
]
string
InternalURLs
[
]
string
ProxyResources
[
]
ProxyResource
Resources
ResourceResolver
WasmContentLength
string
WasmContentLengthHeader
string
ServiceWorkerTemplate
string
-
StartURLis the manifest'sstart_url, the page an installed app opens on. It defaults to"/". -
Envis a set of variables for the app.app.Getenv(k)reads them in the browser, and on the server, where the handler also sets them in the process environment when it initialises. They are written intoapp.js, so never put secrets inEnv. The handler overwrites four keys of its own:GOAPP_VERSION,GOAPP_STATIC_RESOURCES_URL,GOAPP_ROOT_PREFIXandGOAPP_INTERNAL_URLS. -
InternalURLsare URL prefixes that open with a full page load in the same tab. Without them, a link to another host opens in a new tab, and a link to the same host is routed inside the app. -
ProxyResourcesandResourcesare covered under Static resources . -
WasmContentLengthis the size ofapp.wasmin bytes, as a string. The loader uses it for the progress label when the response has no usable length, for example when it is compressed. Otherwise the loader reads the header named byWasmContentLengthHeader, thenContent-Length. -
ServiceWorkerTemplatereplaces the service worker. It defaults toapp.DefaultAppWorkerJS. A custom template loses WebGo's update handling, under Versions and updates , unless it copies it.
WebGo fields
WebDir
string
DisableAutoUpdate
bool
Version
string
func
(
h
*
Handler
)
Build
(
)
error
WebDir
and
Build
are covered under
Handler and Build
.
Version
and
DisableAutoUpdate
are covered under
Versions and updates
.
What it serves
-
/app.js,/app-worker.js,/manifest.webmanifest,/wasm_exec.jsand/app.css, generated from the fields above./goapp.jsand/manifest.jsonare aliases. -
/web/...from disk, whenResourcesis a local directory./app.wasmis an alias of/web/app.wasm. -
/robots.txt,/sitemap.xml,/ads.txtand everyProxyResourcespath. - Library stylesheets, under Libraries .
-
Any other path is a page. A path no
app.Routeorapp.RouteWithRegexpmatches gets a plain 404.
Every response has
Cache-Control: no-cache
. Everything except
/web/
files and proxied files also has the version as its
ETag
, and a request that sends it back gets
304 Not Modified
.
/web/
files are validated by their modification time instead.