-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (54 loc) · 1.08 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"fmt"
"log"
"net/http"
"github.com/maxence-charriere/go-app/v9/pkg/app"
svg "github.com/nathanhack/go-app-svg"
"github.com/nathanhack/go-app-svg/attr"
)
type circle struct {
app.Compo
clicked bool
}
func (c *circle) OnClick(ctx app.Context, e app.Event) {
c.clicked = !c.clicked
c.Render()
}
func (c *circle) Render() app.UI {
return app.Div().Body(
svg.Svg(
attr.Width(300),
attr.Height(100),
attr.ViewBox(0, 0, 300, 100),
attr.If(c.clicked, attr.Fill("grey"), attr.Fill("black")),
attr.Stroke("red"),
svg.Circle(
attr.Cx(50),
attr.Cy(50),
attr.R(40),
),
svg.If(c.clicked, svg.Circle(
attr.Cx(150),
attr.Cy(50),
attr.R(4),
attr.Fill("purple"),
), nil),
),
)
}
func main() {
// Components routing:
app.Route("/", &circle{})
app.RunWhenOnBrowser()
// HTTP routing:
http.Handle("/", &app.Handler{
Name: "Circle",
Description: "Example",
})
port := 8000
fmt.Printf("http://localhost:%v", port)
if err := http.ListenAndServe(fmt.Sprintf(":%v", port), nil); err != nil {
log.Fatal(err)
}
}