-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (37 loc) · 1.43 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"github.com/maxence-charriere/go-app/v9/pkg/app"
)
// hello is a component that displays a simple "Hello World!". A component is a
// customizable, independent, and reusable UI element. It is created by
// embedding app.Compo into a struct.
type hello struct {
app.Compo
}
// The Render method is where the component appearance is defined. Here, a
// "Hello World!" is displayed as a heading.
func (h *hello) Render() app.UI {
return app.H1().Text("Hello World!")
}
func main() {
// The first thing to do is to associate the hello component with a path.
//
// This is done by calling the Route() function, which tells go-app what
// component to display for a given path, on both client and server-side.
app.Route("/", &hello{})
// Once the routes set up, the next thing to do is to either launch the app
// or the server that serves the app.
//
// When executed on the client-side, the RunWhenOnBrowser() function
// launches the app, starting a loop that listens for app events and
// executes client instructions. Since it is a blocking call, the code below
// it will never be executed.
//
// When executed on the server-side, RunWhenOnBrowser() does nothing, which
// lets room for server implementation without the need for precompiling
// instructions.
app.RunWhenOnBrowser()
// this will depend on the target (wasm or not wasm) and
// it starts the servers if it is not the wasm target.
AppServer()
}