/
server.go
51 lines (44 loc) · 1.01 KB
/
server.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
package demoslandingvideo
import (
"net/http"
"github.com/yosssi/ace"
"appengine"
)
// Magic values for the template engine
func appEngineEnvironment(e string) string {
if appengine.IsDevAppServer() {
if e == "isDevelopment" {
return "true"
} else {
return ""
}
} else {
if e == "isProduction" {
return "true"
} else {
return ""
}
}
}
func homeHandler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
data := map[string]string{
"isDevelopment": appEngineEnvironment("isDevelopment"),
"isProduction": appEngineEnvironment("isProduction"),
"currentHostname": appengine.DefaultVersionHostname(c),
}
tpl, err := ace.Load("base", "inner", &ace.Options{
BaseDir: "views",
DynamicReload: true})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if err := tpl.Execute(w, data); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
func init() {
http.HandleFunc("/", homeHandler)
}