add page error when file don't exists

This commit is contained in:
arnaucube
2019-05-08 21:46:25 +02:00
parent a0b3d071e5
commit 1eec2da173
4 changed files with 27 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
package main
import (
"fmt"
"html/template"
"log"
"net/http"
@@ -60,6 +61,11 @@ func getPage(w http.ResponseWriter, r *http.Request) {
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)
}