2015-09-24 01:44:49 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2015-09-24 02:08:44 -04:00
|
|
|
"github.com/flosch/pongo2"
|
2015-09-24 01:44:49 -04:00
|
|
|
"github.com/zenazn/goji/web"
|
|
|
|
)
|
|
|
|
|
2015-09-25 12:00:14 -04:00
|
|
|
func indexHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
2015-09-28 20:46:58 -04:00
|
|
|
err := Templates["index.html"].ExecuteWriter(pongo2.Context{}, w)
|
2015-09-24 01:44:49 -04:00
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
}
|
|
|
|
}
|
2015-09-25 12:00:14 -04:00
|
|
|
|
2015-09-30 00:56:51 -04:00
|
|
|
func pasteHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
|
|
|
err := Templates["paste.html"].ExecuteWriter(pongo2.Context{}, w)
|
|
|
|
if err != nil {
|
|
|
|
oopsHandler(c, w, r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-25 12:00:14 -04:00
|
|
|
func notFoundHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.WriteHeader(404)
|
2015-09-28 20:46:58 -04:00
|
|
|
err := Templates["404.html"].ExecuteWriter(pongo2.Context{}, w)
|
2015-09-25 12:00:14 -04:00
|
|
|
if err != nil {
|
|
|
|
oopsHandler(c, w, r)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func oopsHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
2015-09-28 23:46:43 -04:00
|
|
|
w.WriteHeader(500)
|
2015-09-28 20:46:58 -04:00
|
|
|
err := Templates["oops.html"].ExecuteWriter(pongo2.Context{}, w)
|
2015-09-25 12:00:14 -04:00
|
|
|
if err != nil {
|
|
|
|
oopsHandler(c, w, r)
|
|
|
|
}
|
|
|
|
}
|
2015-09-28 23:46:43 -04:00
|
|
|
|
|
|
|
func unauthorizedHandler(c web.C, w http.ResponseWriter, r *http.Request) {
|
|
|
|
w.WriteHeader(401)
|
|
|
|
err := Templates["401.html"].ExecuteWriter(pongo2.Context{}, w)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
}
|
|
|
|
}
|