add page error when file don't exists
arnaucube arnaucube@gmail.com
Wed, 08 May 2019 21:46:25 +0200
4 files changed,
27 insertions(+),
1 deletions(-)
M
main.go
→
main.go
@@ -1,6 +1,7 @@
package main import ( + "fmt" "html/template" "log" "net/http"@@ -59,6 +60,11 @@ vars := mux.Vars(r)
path := vars["path"] path = strings.Replace(path, "%", "/", -1) log.Println(path) + + if len(strings.Split(path, ".")) < 2 { + fmt.Fprintf(w, errTemplate) + return + } if strings.Split(path, ".")[1] != "md" { http.ServeFile(w, r, path)
M
template.go
→
templates.go
@@ -74,3 +74,24 @@ </script>
</body> </html> ` + +const errTemplate = ` +<!DOCTYPE html> +<html> +<title>{{.Title}}</title> +<style> +body { + font-family: Arial, Helvetica, sans-serif; + background:#000000; + color:#cccccc; +} +</style> +<body> + +<h3>File doesn't exist</h3> +<br><br> +<a href="/">Back to dir menu</a> + +</body> +</html> +`