This repository has been archived by the owner on Jan 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
main.go
61 lines (48 loc) · 1.33 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
package main
import (
"bytes"
"html/template"
"log"
"net/http"
"github.com/beyondblog/k8s-web-terminal/Godeps/_workspace/src/github.com/Joker/jade"
)
func handler(w http.ResponseWriter, r *http.Request) {
jade_tpl, err := jade.ParseFile("template.jade")
if err != nil {
log.Printf("\nParseFile error: %v", err)
}
log.Printf("%s\n\n", jade_tpl)
//
funcMap := template.FuncMap{
"include": func(includePath string) (template.HTML, error) {
include_tpl, err := jade.ParseFile(includePath)
if err != nil {
log.Printf("\nParseFile error: %v", err)
}
log.Printf("%s\n\n", include_tpl)
go_partial_tpl, _ := template.New("partial").Parse(include_tpl)
buf := new(bytes.Buffer)
go_partial_tpl.Execute(buf, "")
return template.HTML(buf.String()), nil
},
"bold": func(content string) (template.HTML, error) {
return template.HTML("<b>" + content + "</b>"), nil
},
}
//
go_tpl, err := template.New("html").Funcs(funcMap).Parse(jade_tpl)
if err != nil {
log.Printf("\nTemplate parse error: %v", err)
}
err = go_tpl.Execute(w, "")
if err != nil {
log.Printf("\nExecute error: %v", err)
}
}
func js(w http.ResponseWriter, r *http.Request) {}
func main() {
log.Println("open http://localhost:8080/")
http.HandleFunc("/javascripts/", js)
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}