-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
html.go
executable file
·98 lines (81 loc) · 1.96 KB
/
html.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
// File generated by Gopher Sauce
// DO NOT EDIT!!
package handlers
import (
"log"
"net/http"
"strings"
gosweb "github.com/cheikhshift/gos/web"
"github.com/gorilla/sessions"
templates "github.com/thestrukture/IDE/api/templates"
sessionStore "github.com/thestrukture/IDE/api/sessions"
)
// Access you .gxml's end tags with
// this http.HandlerFunc.
// Use MakeHandler(http.HandlerFunc) to serve your web
// directory from memory.
func MakeHandler(fn func(http.ResponseWriter, *http.Request)) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if attmpt := ApiAttempt(w, r); !attmpt {
fn(w, r)
}
}
}
func Handler(w http.ResponseWriter, r *http.Request) {
var p *gosweb.Page
p, err := templates.LoadPage(r.URL.Path)
var session *sessions.Session
var er error
if session, er = sessionStore.Store.Get(r, "session-"); er != nil {
session, _ = sessionStore.Store.New(r, "session-")
}
if err != nil {
log.Println(err.Error())
w.WriteHeader(http.StatusNotFound)
pag, err := templates.LoadPage("")
if err != nil {
log.Println(err.Error())
//
return
}
pag.R = r
pag.Session = session
if p != nil {
p.Session = nil
p.Body = nil
p.R = nil
p = nil
}
if pag.IsResource {
w.Write(pag.Body)
} else {
templates.RenderTemplate(w, pag) //""
}
session = nil
return
}
if !p.IsResource {
w.Header().Set("Content-Type", "text/html")
p.Session = session
p.R = r
templates.RenderTemplate(w, p) //fmt.Sprintf("web%s", r.URL.Path)
session.Save(r, w)
// log.Println(w)
} else {
w.Header().Set("Cache-Control", "public")
if strings.Contains(r.URL.Path, ".css") {
w.Header().Add("Content-Type", "text/css")
} else if strings.Contains(r.URL.Path, ".js") {
w.Header().Add("Content-Type", "application/javascript")
} else {
w.Header().Add("Content-Type", http.DetectContentType(p.Body))
}
w.Write(p.Body)
}
p.Session = nil
p.Body = nil
p.R = nil
p = nil
session = nil
return
}