Add simple error 404 page.

This commit is contained in:
A. Svensson 2016-04-21 15:23:46 +02:00
parent e526cff3e7
commit 23d2d3c75c
3 changed files with 16 additions and 4 deletions

View File

@ -19,7 +19,7 @@ func (i *Instance) Serve(addr string) error {
gin.SetMode(gin.ReleaseMode) gin.SetMode(gin.ReleaseMode)
} }
// TODO: replace Default with New and use custom logger and stuff // TODO: replace Default with New and use custom logger and stuff?
i.router = gin.Default() i.router = gin.Default()
// Load templates // Load templates
@ -42,6 +42,7 @@ func (i *Instance) Serve(addr string) error {
i.router.Static("/static", "./static") i.router.Static("/static", "./static")
i.router.GET("/", i.server_index) i.router.GET("/", i.server_index)
i.router.GET("/error", i.page_error)
i.router.GET("/server/:server_id/*slug", i.server_detail) i.router.GET("/server/:server_id/*slug", i.server_detail)
i.router.GET("/server/:server_id", i.server_detail) i.router.GET("/server/:server_id", i.server_detail)
@ -60,14 +61,16 @@ func (i *Instance) server_index(c *gin.Context) {
}) })
} }
func (i *Instance) page_error(c *gin.Context) {
c.HTML(http.StatusNotFound, "error_404.html", nil)
}
func (i *Instance) server_detail(c *gin.Context) { func (i *Instance) server_detail(c *gin.Context) {
id, err := strconv.ParseInt(c.Param("server_id"), 10, 0) id, err := strconv.ParseInt(c.Param("server_id"), 10, 0)
check_error(err) check_error(err)
s, err := i.DB.GetServer(int(id)) s, err := i.DB.GetServer(int(id))
if err != nil { if err != nil {
// TODO c.Redirect(http.StatusTemporaryRedirect, "/error")
//c.HTML(http.StatusNotFound, "error_404.html", nil)
c.String(http.StatusNotFound, "Server not found")
return return
} }
type weekday struct { type weekday struct {

View File

@ -138,6 +138,10 @@ body {
float: left; float: left;
} }
.center {
text-align: center;
}
.bold { .bold {
font-weight: bold; font-weight: bold;
} }

5
templates/error_404.html Normal file
View File

@ -0,0 +1,5 @@
{{template "header" .}}
<p class="center">Sorry captain, can't find that page for you!</p>
{{template "footer"}}