This repository was archived by the owner on Mar 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexampleserver.go
78 lines (72 loc) · 3.5 KB
/
exampleserver.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
package main
import (
"net/http"
"log"
"html/template"
"./gocomponents"
)
// The index function serves at localhost:9090/
func index(w http.ResponseWriter, r *http.Request) {
// Parse required files
t, err := template.ParseFiles("./templates/index.html", "./gocomponents/templates/header.html", "./gocomponents/templates/sidebar.html", "./gocomponents/templates/colors.html")
// Make sure there are no errors
if err != nil {
log.Fatal(err)
}
// Data for the template
data := gocomponents.TemplateData{
SiteTitle: "Kees",
Colors: map[string]string{
"primary": "#2196F3",
"primaryDark": "#1976D2",
"primaryText": "#FFFFFF",
"accent": "#FF6E40",
"accentText": "#000000",
},
HasSidebar: true,
SidebarItems: map[string]string{
"kaas": "Kaas",
"kees-btn": "Koel",
},
Components: map[string]template.HTML{
"MyCard": gocomponents.Card("henk jan", "<h1>kees</h1>"),
"MyButton": gocomponents.Button("primary-btn", "klikkie"),
"MyButtonTwo": gocomponents.Button("accent-btn", "klikkie"),
"MyButtonThree": gocomponents.Button("flat-btn", "klikkie"),
"MyCheckbox": gocomponents.CheckBox("myCheckbox", "kees", "Free YT money?"),
"MyRadio": gocomponents.Radio("myRadio", "jan henk", "Radio button"),
"MyInput": gocomponents.Input("myInput", "kees henk", "Your name", -1),
"MyList": gocomponents.List("kees-list", map[string]string{
"Pizza": "omnom",
"More pizza": "extra omnom",
"Infinite pizza": "ultramegaomnom",
}),
"MyProgressBar": gocomponents.ProgressBar("kees-bar", "Progress", false),
"MyTabGroup": gocomponents.TabGroup("kees is-cool", map[string]string{
"tabName": "kees",
"tabContent": "<p>cool</p>",
},
map[string]string{
"tabName": "Henk",
"tabContent": "Oh boi",
}),
"MyMenu": gocomponents.Menu("kees-menu", "MyMenu", map[string]string{
"item-one": "Item ONEEE",
"item-two": "WE ARE NUMBER TWO",
}),
"MyActionButton": gocomponents.FloatingActionButton("my-action-btn", "add"),
"CompleteCard": gocomponents.Card("complete-card", `
<h3>kees</h3>
` + string(gocomponents.Button("kees iscool", "klikkie")) + `
<p>Cool, ain't it?</p>
`),
},
}
// Execute templates
t.ExecuteTemplate(w, "layout", data)
}
func main() {
http.HandleFunc("/static/", gocomponents.ServeStatic)
http.HandleFunc("/", index)
http.ListenAndServe(":9090", nil)
}