From 95afa389bc54b26ef5fb970b9b22f3c2d70def1d Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Thu, 23 Mar 2017 07:32:40 -0600 Subject: [PATCH] Simplify routes, handle error route Former-commit-id: a2be41df36132865f1f5ddee954a2c36cd15946a [formerly 952889d5fec4f3207cfd3a071bcf7278afeb09a8] [formerly 21c56db9a4a329ff6e70573734bbe7a33ee8b0a0 [formerly 9becf077453cf5539c289c90574f3ac400ae1dee]] Former-commit-id: 1ad7a875ff4738230e09a4d46bf58c7d03c43a90 [formerly 5263a10dd6b8057bcfa7ac65509c7a87d5889175] Former-commit-id: 57c32446567ef6b8d219893ed93c6499cf0b0da8 --- handlers.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/handlers.go b/handlers.go index a46ebc1..eaf2111 100755 --- a/handlers.go +++ b/handlers.go @@ -57,7 +57,9 @@ func loadTemplates(list ...string) multitemplate.Render { func handlePageRequest(c *gin.Context) { page := c.Param("page") command := c.Param("command") - + if len(command) < 2 { + command = "/ " + } // Serve static content from memory if page == "static" { filename := page + command @@ -103,7 +105,7 @@ func handlePageRequest(c *gin.Context) { versionsText[i] = time.Unix(v/1000000000, 0).String() } - if command == "/raw" { + if command[0:2] == "/r" { c.Writer.Header().Set("Content-Type", contentType(p.Name)) c.Writer.Header().Set("Access-Control-Allow-Origin", "*") c.Writer.Header().Set("Access-Control-Max-Age", "86400") @@ -114,11 +116,19 @@ func handlePageRequest(c *gin.Context) { return } log.Debug(command) + log.Debug("%v", command[0:2] != "/e" && + command[0:2] != "/v" && + command[0:2] != "/l" && + command[0:2] != "/h") c.HTML(http.StatusOK, "index.tmpl", gin.H{ - "EditPage": command == "/edit", - "ViewPage": command == "/view", - "ListPage": command == "/list", - "HistoryPage": command == "/history", + "EditPage": command[0:2] == "/e", // /edit + "ViewPage": command[0:2] == "/v", // /view + "ListPage": command[0:2] == "/l", // /list + "HistoryPage": command[0:2] == "/h", // /history + "DontKnowPage": command[0:2] != "/e" && + command[0:2] != "/v" && + command[0:2] != "/l" && + command[0:2] != "/h", "Page": p.Name, "RenderedPage": template.HTML([]byte(rawHTML)), "RawPage": rawText, @@ -127,6 +137,7 @@ func handlePageRequest(c *gin.Context) { "IsLocked": p.IsLocked, "IsEncrypted": p.IsEncrypted, "ListItems": renderList(rawText), + "Route": "/" + page + command, }) }