OLD | NEW |
1 package frontend | 1 package frontend |
2 | 2 |
3 import ( | 3 import ( |
4 "html/template" | 4 "html/template" |
5 "net/http" | 5 "net/http" |
6 "time" | 6 "time" |
7 | 7 |
8 "google.golang.org/appengine" | 8 "google.golang.org/appengine" |
9 | 9 |
10 "github.com/luci/luci-go/appengine/gaemiddleware" | 10 "github.com/luci/luci-go/appengine/gaemiddleware" |
11 "github.com/luci/luci-go/server/router" | 11 "github.com/luci/luci-go/server/router" |
12 "github.com/luci/luci-go/server/templates" | 12 "github.com/luci/luci-go/server/templates" |
13 ) | 13 ) |
14 | 14 |
15 func init() { | 15 func init() { |
16 r := router.New() | 16 r := router.New() |
17 baseMW := base() | 17 baseMW := base() |
18 | 18 |
19 » r.GET("/testfile", baseMW, GetHandler) | 19 » r.GET("/testfile", baseMW, getHandler) |
20 » r.GET("/testfile/", baseMW, GetHandler) | 20 » r.GET("/testfile/", baseMW, getHandler) |
21 | 21 |
22 http.DefaultServeMux.Handle("/", r) | 22 http.DefaultServeMux.Handle("/", r) |
23 } | 23 } |
24 | 24 |
25 // base returns the root middleware chain. | 25 // base returns the root middleware chain. |
26 func base() router.MiddlewareChain { | 26 func base() router.MiddlewareChain { |
27 templateBundle := &templates.Bundle{ | 27 templateBundle := &templates.Bundle{ |
28 Loader: templates.FileSystemLoader("templates"), | 28 Loader: templates.FileSystemLoader("templates"), |
29 DebugMode: appengine.IsDevAppServer(), | 29 DebugMode: appengine.IsDevAppServer(), |
30 FuncMap: template.FuncMap{ | 30 FuncMap: template.FuncMap{ |
31 "timeParams": func(t time.Time) string { | 31 "timeParams": func(t time.Time) string { |
32 return t.Format(paramsTimeFormat) | 32 return t.Format(paramsTimeFormat) |
33 }, | 33 }, |
34 "timeJS": func(t time.Time) int64 { | 34 "timeJS": func(t time.Time) int64 { |
35 return t.Unix() * 1000 | 35 return t.Unix() * 1000 |
36 }, | 36 }, |
37 }, | 37 }, |
38 } | 38 } |
39 | 39 |
40 return gaemiddleware.BaseProd().Extend( | 40 return gaemiddleware.BaseProd().Extend( |
41 templates.WithTemplates(templateBundle), | 41 templates.WithTemplates(templateBundle), |
42 ) | 42 ) |
43 } | 43 } |
OLD | NEW |