The short version
- There is no v0.2.0. Everything planned for it, and everything planned after it, is in v1.0.0.
-
Any component can implement
OnLoad. It is not drawn until its load is done. -
app.Screen,app.Shellandapp.Modelreplace thepageanddatapackages. -
Scripts: list ES modules on
Handler.Importsand call them from Go throughscript.Use. - Feature flags: an OpenFeature SDK in Go that runs in the browser.
-
dev.RunDevServerserves your site locally and rebuilds it when you save. - WebGo is MIT now, and the docs got a new coat of ink.
-
Breaking:
pageanddataare deleted. One list gets you across, and you only cross once.
Hey everyone,
This is the big one. When we brought go-app's engine into WebGo in 0.1.0, we wrote down what had to be true before we'd call it 1.0: keep everything that worked, move pages into the engine, let components load before they draw, give JavaScript modules a typed door, and ship feature flags that run in the browser. Every line of that list is done. So this update is 1.0.0.
Wait, what happened to 0.2.0?
If you've been reading the README or these docs over the last two weeks, you saw
v0.2.0
everywhere. It even had a name, Moving Day, and an article sitting right here. It was real, it just never got a tag.
The plan was two steps. 0.2.0 would move pages into the engine and add loading and scripts. Then feature flags would follow, and that would be 1.0. We finished the first step on 9 November and rewrote the docs for it the next day. But we held the tag, because the flags work was already under way and it reached into the same places.
Then the flags work finished too. Two days after the docs said 0.2.0, the last thing between it and 1.0 was done, and the dev server we'd filed under extras showed up as well. At that point 0.2.0 would have been a tag with a shelf life of about a week, and it would have cost you something real: it deletes two packages. You'd migrate to it, and then update again right after.
So we skipped it. One breaking release instead of two, and one migration guide. If you're on 0.1.0, your next stop is 1.0.0. Nothing was dropped on the way: everything that article promised is below.
Load before you draw
This is the one that started it. A screen that wanted its data before it drew used to fake it with flags, because the engine wasn't ours to teach. Now any component can implement
OnLoad
. It runs in the browser, on its own goroutine, after
OnMount
and again after
OnUpdate
, and the component isn't drawn until it returns. Give it a
Loading()
to show something meanwhile, and an
Error(err)
for when the load fails.
func
(
p
*
profileCard
)
OnLoad
(
ctx
app
.
Context
)
error
{
return
fetchProfile
(
ctx
,
&
p
.
profile
)
}
func
(
p
*
profileCard
)
Loading
(
)
app
.
UI
{
return
app
.
Text
(
"Loading…"
)
}
The wait is per component. Its siblings and its parents keep rendering, so parts of one page can load on their own clocks. The State page has a live demo of two of them side by side.
One thing it doesn't do yet: keep the old screen up while the next one loads. You get the new screen's
Loading()
in between. That part isn't built yet.
Pages in the core
The
page
and
data
packages were written on top of go-app, from the outside. Their ideas now live in
app
, next to
Compo
, where the engine can drive them. A screen fetches its data with
WithLoader
:
profileScreen
:=
app
.
NewScreen
[
Profile
]
(
"/profile"
)
.
WithLayout
(
&
profileLayout
{
}
)
.
WithModel
(
profile
)
.
WithLoader
(
fetchProfile
)
One
Shell
is the root for the whole app, and
app.Serve
registers every screen's route for you. In the browser the shell is built once and kept across navigations: moving between pages switches the screen, it doesn't rebuild everything.
Every
Set
on a model now fires the action named after its key, so styles bound to that key follow the state with no
OnAction
call to remember.
Loading before drawing, pages in the engine, typed scripts, feature flags and a dev server. All of it lands at once as v1.0.0, and v0.2.0 never happens. Here's the whole story.
Scripts, typed
Need a JavaScript library? Declare it as a module: a Go type that says where it comes from and what Go gets back. List it on
Handler.Imports
, and the handler writes one importmap so the browser fetches it while
app.wasm
downloads.
type
Confetti
struct
{
}
func
(
Confetti
)
Source
(
)
app
.
ModuleSource
{
return
script
.
CDN
(
"npm"
,
"canvas-confetti"
,
"1.9.3"
)
}
func
(
Confetti
)
Init
(
ctx
app
.
Context
,
mod
app
.
Value
)
Cannon
{
return
Cannon
{
fire
:
mod
.
Get
(
"default"
)
}
}
From then on
script.Use(ctx, Confetti{})
hands you a
Cannon
, typed, with a
bool
that is
false
when the module didn't load.
script.Local
serves a file from your own
web
directory the same way. The
Scripts page
has the whole thing, with a button that fires confetti.
Feature flags
This is the piece 0.2.0 was waiting for. OpenFeature is the vendor-neutral standard for feature flags, and its official Go SDK only runs on servers. So we wrote one from scratch that runs in the browser: one API, clients, hooks, events and an evaluation context.
on
:=
openfeature
.
GetClient
(
)
.
Boolean
(
"new-nav"
,
false
)
If anything goes wrong, you get the default you passed. Three providers come with it:
memprovider
keeps flags in memory for tests and local work,
jsprovider
wraps any JavaScript OpenFeature web provider, and
flipt
loads the official Flipt one for you.
We were stubborn about this one. It follows the OpenFeature specification v0.9.0, and a test walks every requirement in it. On top of that, the same scenarios run against the official Web SDK and against ours, and what each one evaluates, emits and logs has to match. The handful of places where Go has to differ are listed on the Feature flags page , one by one. That's most of why it took as long as it did, and why 0.2.0 kept waiting.
A dev server
We had this down as an extra for after 1.0. It got done early, so here it is.
dev.RunDevServer
builds your static site, serves it, and rebuilds when you save a Go file or anything in
web
.
err
:=
dev
.
RunDevServer
(
ctx
,
".dev"
,
"localhost:8000"
,
func
(
dir
string
)
*
exec
.
Cmd
{
return
exec
.
Command
(
"go"
,
"run"
,
"."
,
"-static"
,
dir
)
}
)
Break the build and it tells you, and keeps serving the last one that worked. Fix it, switch back to your tab, and the page moves to the new build by itself. This site's own
go run . dev
is built on it.
Running locally
has a full
main
to copy.
A new coat of ink
You may have noticed the place looks different. The docs are a riso zine now: paper grain, off-register titles, taped-on code printouts. The pages themselves are written in Go instead of markdown, which is how every example on them can be a live component and not a screenshot. All of it is styled with WebGo's own typed CSS.
A word on the license, again
In 0.1.0 we moved to the GPL-3.0. We've changed our minds: WebGo is MIT as of this release. Use it in anything, open source or not. The go-app code inside was MIT all along, and the NOTICE file still credits it.
What's gone
-
The
pageanddatapackages. -
OnAction, and theContent()method screens had. A screen is a component now, and it draws withRender. -
The shell working out its own mount point. It reads
GOAPP_ROOT_PREFIX, whichapp.Handlersets fromResources, soBasePath()is gone too.
How to update
-
page.NewPagebecomesapp.NewScreen. -
page.NewBase(layout, model, []page.Screen{...})becomesapp.NewShell(layout, model, screens...), returned from the function you pass toapp.Serve. -
data.NewViewModelanddata.ViewModel[T]becomeapp.NewModelandapp.Model[T].data.Action[T]becomesapp.Change[T]. -
page.Layout[T]becomesapp.Layout[T], andpage.Screenbecomesapp.Routed. -
Delete every
OnActioncall. If you usedBasePath(), readapp.Getenv("GOAPP_ROOT_PREFIX")instead.
The migration guide has the before and after. The import path stays the same.
What 1.0 means
It means the list we wrote down is finished, and that we're done moving your furniture. From here, a change that breaks your code needs a 2.0, and we're in no hurry to write one.
Get it
go get github.com/Toms223/WebGo@v1.0.0
That's the first edition. Print something with it and tell us what smudged. See you next update.
End of issue 1.0.0
03