|
@@ -2,16 +2,30 @@ package server
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"net/http"
|
|
"net/http"
|
|
|
|
|
+ "os"
|
|
|
|
|
+ "path/filepath"
|
|
|
|
|
+ "strings"
|
|
|
|
|
|
|
|
"git.linuxit.ro/turos.robert/mynotes/lib/inout"
|
|
"git.linuxit.ro/turos.robert/mynotes/lib/inout"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func Wildcard(w http.ResponseWriter, r *http.Request) {
|
|
func Wildcard(w http.ResponseWriter, r *http.Request) {
|
|
|
- if r.Method != "GET" {
|
|
|
|
|
- w.Write(inout.FileToBytes("templates/index.tmpl"))
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if r.Method == "GET" {
|
|
|
|
|
+ endpoint := strings.TrimPrefix(r.URL.Path, "/")
|
|
|
|
|
+ if endpoint == "" {
|
|
|
|
|
+ //in cazul in care apelam root
|
|
|
|
|
+ endpoint = "index"
|
|
|
|
|
+ }
|
|
|
|
|
+ path := filepath.Join("templates", endpoint+".tmpl")
|
|
|
|
|
+ _, err := os.Stat(path)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ w.WriteHeader(http.StatusNotFound)
|
|
|
|
|
+ w.Write(inout.FileToBytes("templates/error.tmpl"))
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ w.Write(inout.FileToBytes(path))
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- w.WriteHeader(http.StatusMethodNotAllowed)
|
|
|
|
|
- w.Write(inout.FileToBytes("templates/error.tmpl"))
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|