404s, admin panel route and removal of old data structure
Signed-off-by: Martyn Ranyard <m@rtyn.berlin>
This commit is contained in:
parent
408516ecea
commit
e989b8454b
|
@ -26,6 +26,7 @@ func HealthHandler(response http.ResponseWriter, request *http.Request) {
|
||||||
|
|
||||||
func NotFoundHandler(response http.ResponseWriter, request *http.Request) {
|
func NotFoundHandler(response http.ResponseWriter, request *http.Request) {
|
||||||
response.Header().Add("X-Template-File", "html"+request.URL.Path)
|
response.Header().Add("X-Template-File", "html"+request.URL.Path)
|
||||||
|
response.WriteHeader(404)
|
||||||
tmpl := template.Must(template.ParseFiles("web/404.html"))
|
tmpl := template.Must(template.ParseFiles("web/404.html"))
|
||||||
tmpl.Execute(response, nil)
|
tmpl.Execute(response, nil)
|
||||||
}
|
}
|
||||||
|
@ -72,7 +73,7 @@ func TemplateHandler(response http.ResponseWriter, request *http.Request) {
|
||||||
// NotFoundHandler(response, request)
|
// NotFoundHandler(response, request)
|
||||||
// return
|
// return
|
||||||
}
|
}
|
||||||
var td = TemplateData{ircBot.Prompts[rand.Intn(len(ircBot.Prompts))], len(ircBot.Prompts), len(ircBot.Credentials.Channels), 0}
|
var td = TemplateData{ircBot.Prompts[rand.Intn(len(ircBot.Prompts))], len(ircBot.Prompts), 0, 0}
|
||||||
err = tmpl.Execute(response, td)
|
err = tmpl.Execute(response, td)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(response, err.Error(), http.StatusInternalServerError)
|
http.Error(response, err.Error(), http.StatusInternalServerError)
|
||||||
|
@ -80,6 +81,11 @@ func TemplateHandler(response http.ResponseWriter, request *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AdminHandler(response http.ResponseWriter, request *http.Request) {
|
||||||
|
request.URL.Path = "/index.html"
|
||||||
|
TemplateHandler(response, request)
|
||||||
|
}
|
||||||
|
|
||||||
func HandleHTTP(passedIrcBot irc.KardBot) {
|
func HandleHTTP(passedIrcBot irc.KardBot) {
|
||||||
ircBot = passedIrcBot
|
ircBot = passedIrcBot
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
|
@ -89,6 +95,7 @@ func HandleHTTP(passedIrcBot irc.KardBot) {
|
||||||
r.HandleFunc("/healthz", HealthHandler)
|
r.HandleFunc("/healthz", HealthHandler)
|
||||||
r.HandleFunc("/example/{.*}", TemplateHandler)
|
r.HandleFunc("/example/{.*}", TemplateHandler)
|
||||||
r.HandleFunc("/cover.css", CSSHandler)
|
r.HandleFunc("/cover.css", CSSHandler)
|
||||||
|
r.HandleFunc("/admin/{channel}/{key}", AdminHandler)
|
||||||
http.Handle("/", r)
|
http.Handle("/", r)
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Handler: loggedRouter,
|
Handler: loggedRouter,
|
||||||
|
|
Loading…
Reference in New Issue