/
main.go
150 lines (142 loc) · 4.36 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package main
import (
"fmt"
"log"
"net/http"
"github.com/pjotrscholtze/go-bootstrap/cmd/go-bootstrap/bootstrap"
"github.com/pjotrscholtze/go-bootstrap/cmd/go-bootstrap/builder"
"github.com/pjotrscholtze/go-bootstrap/cmd/go-bootstrap/htmlwrapper"
)
type User struct {
Username string
Password *string
ID int
Status string
}
func main() {
p := User{
ID: 1,
Username: "Foo",
Status: "Online",
}
ft := builder.NewAdvancedTableBuilder[User]([]User{
p,
{
ID: 2,
Username: "John",
Status: "Offline",
},
{
ID: 3,
Username: "Test",
Status: "Disabled",
},
})
he := builder.NewFormBuilder[User](p).SetDefaultMappings().ActionMethod(builder.HTTPMethodGet, "/")
tb := ft.GetTableBuilder()
tb.GetTableMapping().RemoveByFieldName("Password").Set("ID", "Id").MoveToIndex("ID", 0)
pagination := ft.GetPaginationBuilder()
pagination.SetResultCount(23).SetCurrentPage(1).SetResultsPerPageOptions([]int{
10,
25,
50,
100,
}).SetCurrentResultsPerPage(10)
h := "#"
c := bootstrap.BsColor(bootstrap.BsColorDark)
nv := bootstrap.NavBar("id", c, bootstrap.BsLocationFixedTop, nil, &htmlwrapper.MultiElm{
Contents: []htmlwrapper.Elm{
bootstrap.Nav(true, false, bootstrap.BsNavJustifyContentLeft, bootstrap.BsNavKindNormal, []*bootstrap.NavItem{
{
Content: htmlwrapper.Text("Dashboard"),
DropDownItems: &[]*bootstrap.NavItem{},
Href: &h,
NavState: bootstrap.BsNavStateNormal,
},
{
Content: htmlwrapper.Text("Email"),
DropDownItems: &[]*bootstrap.NavItem{
{
Href: &h,
NavState: bootstrap.BsNavStateNormal,
DropDownItems: &[]*bootstrap.NavItem{},
Content: htmlwrapper.Text("Email"),
},
{
Href: &h,
NavState: bootstrap.BsNavStateNormal,
DropDownItems: &[]*bootstrap.NavItem{},
Content: htmlwrapper.Text("Fail2ban"),
},
},
Href: &h,
NavState: bootstrap.BsNavStateNormal,
},
{
Content: htmlwrapper.Text("FTP"),
DropDownItems: &[]*bootstrap.NavItem{
{
Href: &h,
NavState: bootstrap.BsNavStateNormal,
DropDownItems: &[]*bootstrap.NavItem{},
Content: htmlwrapper.Text("FTP"),
},
{
Href: &h,
NavState: bootstrap.BsNavStateNormal,
DropDownItems: &[]*bootstrap.NavItem{},
Content: htmlwrapper.Text("Fail2ban"),
},
},
Href: &h,
NavState: bootstrap.BsNavStateNormal,
},
}, &c),
},
})
// nv := bootstrap.NavBar("id", bootstrap.BsColorPrimary, bootstrap.BsLocationNormal, nil, bootstrap.Nav(true, true, bootstrap.BsNavJustifyContentLeft, bootstrap.BsNavKindNormal, []*bootstrap.NavItem{
// {
// Href: &h,
// Content: &htmlwrapper.TextElm{Content: "trsting"},
// NavState: bootstrap.BsNavStateNormal,
// DropDownItems: &[]*bootstrap.NavItem{},
// },
// {
// Href: &h,
// Content: &htmlwrapper.TextElm{Content: "a"},
// NavState: bootstrap.BsNavStateNormal,
// DropDownItems: &[]*bootstrap.NavItem{
// {
// Href: &h,
// Content: &htmlwrapper.TextElm{"asdfadfs"},
// DropDownItems: &[]*bootstrap.NavItem{},
// NavState: bootstrap.BsNavStateNormal,
// },
// },
// },
// }))
nvHTML, _ := nv.AsHTML()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
html, err := he.AsElm().AsHTML()
html2, err := ft.AsElm().AsHTML()
// html3, err := pagination.AsElm().AsHTML()
_ = err
fmt.Fprintf(w, `<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap demo</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">
</head>
<body>
`+nvHTML+html+html2+`
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
</body>
</html>`)
})
fmt.Printf("Starting server at port 8085\n")
if err := http.ListenAndServe(":8085", nil); err != nil {
log.Fatal(err)
}
}