Build the whole web app in Go.
WebGo gives you pages, view models, markdown and typed CSS on its own app engine. Routing, state and stylesheets are plain Go that compiles to WebAssembly, so the compiler checks your UI the way it checks your server.
$
go get github.com/Toms223/WebGo@v1.0.0
type
Counter
struct
{ Count
int
}
var
model, _ = app.
NewModel
(
"counter"
, &
Counter
{})
func
(l *Layout)
Draw
(m *app.Model[
Counter
]) app.HTMLDiv {
return
app.Div().Body(
app.H1().Textf(
"%d"
, m.State().Count),
app.Button().Text(
"+1"
).OnClick(l.bump),
)
}
func
(l *Layout)
bump
(ctx app.Context, _ app.Event) {
model.Load(ctx).Apply(
func
(_ app.Context, c *
Counter
) *
Counter
{
c.Count++
return
c
}).Set()
}
Pull the press
Every bump of the counter goes through the three model verbs. Load takes the state, Apply changes it, Set stores it and redraws whatever reads it. This landing page is a Screen, so the press below is its own model.
Four things in the box
Pages and routing
A Shell hosts Screens. Routes, base paths and fragments resolve in the browser, with no server round trip.
View models
Typed state with Load, Apply and Set. Observe it from any component, or react to it from a stylesheet.
Typed CSS
Properties, keywords, media and container queries, keyframes, nesting and layers as Go values. Dead rules never ship.
Markdown with live demos
Render docs from markdown and drop a running Go component into any fence. Every example on this site runs live.
- Go all the way down
- ·
- Compiles to WebAssembly
- ·
- Static site in one command
- ·
- Typed stylesheets
- ·
- Zero JavaScript to write
One language, one mental model.
A screen is a Layout and a Model. The layout draws from the model, handlers apply changes, and the screen re-renders. Styles are values you can pass around, test and reuse.
- Rename a CSS property and the build breaks, not the page.
- Bind a class to state and the dynamic sheet recomputes on its own.
- Ship the generated site to any static host, GitHub Pages included.
var
Button = style.
Class
(
"button"
).
Set
(
css.
Padding
(css.Rem(0.6), css.Rem(1.1)),
css.Border(css.Px(2), kw.Solid, css.Var(
"line"
)),
css.BoxShadow(css.Var(
"shadow"
)),
).
Hover
(css.Transform(css.Raw(
"translate(-2px, -2px)"
))).
Media
(media.MaxWidth(css.Rem(48)), css.Width(css.Pct(100)))
func
(b *Buy)
Render
() app.UI {
return
app.Button().Style(Button).Text(
"Buy"
)
}
$
GOARCH=wasm GOOS=js go build -o web/app.wasm .
./theme.go:14:7: undefined: css.Paddin
...and the compiler catches it before a browser ever sees it.
From go get to a running page
Install
Add WebGo to your module. Everything comes from this one import.
go get github.com/Toms223/WebGo@v1.0.0
Write a page
A component, a route and app.RunWhenOnBrowser. Then grow into Screens and Models.
app.Route("/", func() app.Composer { return &hello{} })
Build and ship
Compile to wasm and generate a static site, or serve it from the same binary.
GOARCH=wasm GOOS=js go build -o web/app.wasm .
Fresh off the drum
06Ready when you are.
The getting started guide takes you from an empty module to a static site. Every example on this site is live.