diff options
author | Jan C <jan@ruken.pw> | 2016-03-28 12:30:15 (UTC) |
---|---|---|
committer | Jan C <jan@ruken.pw> | 2016-03-28 12:30:15 (UTC) |
commit | e8f2412efe55c969390168e3ce0b41200f780a1e (patch) | |
tree | 41a0e692d0ded0113394712f750b730c4f4fa864 /main.go | |
parent | c7f28c0032163075bd21f899c37ae992e3eece80 (diff) |
cache hinzugefuegt. wird derzeit vom lists und grils modul verwendet. versuch die loadingzeit zu verringern (anscheinend wird im hintergrund auf jeder route der index requested, was ziemlich doof ist).
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -17,12 +17,17 @@ import ( | |||
17 | 17 | ||
18 | "github.com/julienschmidt/httprouter" | 18 | "github.com/julienschmidt/httprouter" |
19 | _ "github.com/lib/pq" | 19 | _ "github.com/lib/pq" |
20 | "strings" | ||
20 | ) | 21 | ) |
21 | 22 | ||
22 | var app *grilist.Grilist | 23 | var app *grilist.Grilist |
23 | 24 | ||
24 | func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { | 25 | func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { |
25 | http.Redirect(w, r, "/dashboard", 302) | 26 | if strings.Index(r.Referer(), "127.0.0.1") != -1 { |
27 | w.WriteHeader(200) | ||
28 | return | ||
29 | } | ||
30 | http.Redirect(w, r, "/dashboard", 301) | ||
26 | } | 31 | } |
27 | 32 | ||
28 | func loadModule(mod grilist.Module) error { | 33 | func loadModule(mod grilist.Module) error { |
@@ -61,6 +66,7 @@ func main() { | |||
61 | router, | 66 | router, |
62 | } | 67 | } |
63 | 68 | ||
69 | router.GET("/", index) | ||
64 | router.HandlerFunc("GET", "/login", login.DisplayLogin) | 70 | router.HandlerFunc("GET", "/login", login.DisplayLogin) |
65 | router.HandlerFunc("POST", "/login", login.Login) | 71 | router.HandlerFunc("POST", "/login", login.Login) |
66 | router.HandlerFunc("GET", "/settings", login.DisplayUserSettings) | 72 | router.HandlerFunc("GET", "/settings", login.DisplayUserSettings) |
@@ -68,8 +74,6 @@ func main() { | |||
68 | router.HandlerFunc("GET", "/logout", login.Logout) | 74 | router.HandlerFunc("GET", "/logout", login.Logout) |
69 | router.HandlerFunc("GET", "/register", login.DisplayRegistration) | 75 | router.HandlerFunc("GET", "/register", login.DisplayRegistration) |
70 | router.HandlerFunc("POST", "/register", login.Register) | 76 | router.HandlerFunc("POST", "/register", login.Register) |
71 | router.GET("/", index) | ||
72 | router.GET("/dashboard", viewDashboard) | ||
73 | 77 | ||
74 | fs := http.FileServer(http.Dir("assets")) | 78 | fs := http.FileServer(http.Dir("assets")) |
75 | http.Handle("/assets/", http.StripPrefix("/assets/", fs)) | 79 | http.Handle("/assets/", http.StripPrefix("/assets/", fs)) |
@@ -81,6 +85,7 @@ func main() { | |||
81 | loadModule(tags.New()) | 85 | loadModule(tags.New()) |
82 | loadModule(search.New()) | 86 | loadModule(search.New()) |
83 | loadModule(user.New()) | 87 | loadModule(user.New()) |
88 | router.GET("/dashboard", viewDashboard) | ||
84 | 89 | ||
85 | log.Fatal(http.ListenAndServe(":8080", nil)) | 90 | log.Fatal(http.ListenAndServe(":8080", nil)) |
86 | } | 91 | } |