-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.go
85 lines (76 loc) · 2.46 KB
/
home.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
"log"
"net/http"
"github.com/NYTimes/gziphandler"
"github.com/maxence-charriere/go-app/v9/pkg/app"
)
type home struct {
app.Compo
}
// The Render method is where the component appearance is defined. Here, a
// "pubsub World!" is displayed as a heading.
func (h *home) Render() app.UI {
return app.Div().Class("stack").Body(
app.Div().Class("content card").Body(
app.H1().Body(
app.B().Body(
app.Span().ID("desktop-prompt").Body(
app.Text("Stateless"),
),
app.Span().ID("mobile-prompt").Body(
app.Text("Stateless"),
),
app.Text(" Minds"),
),
),
app.P().Body(
app.Text("We question reality."),
),
),
app.Div().Class("padding card"),
app.Div().Class("border card"),
app.Div().Class("background card"),
app.Div().Class("box-shadow card"),
)
}
// The main function is the entry point where the app is configured and started.
// It is executed in 2 different environments: A client (the web browser) and a
// server.
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("/", &home{})
// 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()
// Finally, launching the server that serves the app is done by using the Go
// standard HTTP package.
//
// The Handler is an HTTP handler that serves the client and all its
// required resources to make it work into a web browser. Here it is
// configured to handle requests with a path that starts with "/".
withGz := gziphandler.GzipHandler(&app.Handler{
Name: "statelessminds",
Description: "Indie startup studio making digital products that question reality.",
Styles: []string{
"/web/app.css",
},
Scripts: []string{},
})
http.Handle("/", withGz)
if err := http.ListenAndServe(":7000", nil); err != nil {
log.Fatal(err)
}
}