-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
98 lines (67 loc) · 2.03 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"fmt"
"net/url"
"github.com/realPy/hogosuru"
"github.com/realPy/hogosuru/base/document"
"github.com/realPy/hogosuru/base/event"
"github.com/realPy/hogosuru/base/formdata"
"github.com/realPy/hogosuru/base/htmlbuttonelement"
"github.com/realPy/hogosuru/base/htmldivelement"
"github.com/realPy/hogosuru/base/htmllinkelement"
"github.com/realPy/hogosuru/base/xmlhttprequest"
)
func OnClickButton() {
endpoint, _ := url.Parse("app/data")
if xhr, err := xmlhttprequest.New(); err == nil {
xhr.Open("POST", endpoint.String())
f, _ := formdata.New()
f.Append("username", "test")
xhr.SetOnload(func(i interface{}) {
if text, err := xhr.ResponseText(); err == nil {
fmt.Printf("Resultat: %s\n", text)
}
if header, err := xhr.GetResponseHeader("Content-Type"); err == nil {
fmt.Printf("Resultat: %s\n", header)
}
})
xhr.Send(f)
}
}
func main() {
hogosuru.Init()
// we get the current document
if doc, err := document.New(); hogosuru.AssertErr(err) {
//we got the head
if head, err := doc.Head(); hogosuru.AssertErr(err) {
if link, err := htmllinkelement.New(doc); hogosuru.AssertErr(err) {
link.SetRel("stylesheet")
link.SetHref("https://cdn.jsdelivr.net/npm/bulma@0.9.3/css/bulma.min.css")
head.AppendChild(link.Node)
}
}
//we get the current body
if body := doc.Body_(); hogosuru.AssertErr(err) {
if div, err := htmldivelement.New(doc); hogosuru.AssertErr(err) {
if list, err := div.ClassList(); hogosuru.AssertErr(err) {
list.Add("buttons")
}
if buttonprimary, err := htmlbuttonelement.New(doc); hogosuru.AssertErr(err) {
buttonprimary.SetTextContent("Primary")
//we get the class list attribute
if list, err := buttonprimary.ClassList(); hogosuru.AssertErr(err) {
list.Add("button")
list.Add("is-primary")
}
buttonprimary.OnClick(func(e event.Event) {
OnClickButton()
})
div.Append(buttonprimary.Element)
}
body.Append(div.Element)
}
}
}
ch := make(chan struct{})
<-ch
}