handlers.go 592 B

12345678910111213141516171819202122232425262728293031
  1. package server
  2. import (
  3. "net/http"
  4. "os"
  5. "path/filepath"
  6. "strings"
  7. "git.linuxit.ro/turos.robert/mynotes/lib/inout"
  8. )
  9. func Wildcard(w http.ResponseWriter, r *http.Request) {
  10. if r.Method == "GET" {
  11. endpoint := strings.TrimPrefix(r.URL.Path, "/")
  12. if endpoint == "" {
  13. //in cazul in care apelam root
  14. endpoint = "index"
  15. }
  16. path := filepath.Join("templates", endpoint+".tmpl")
  17. _, err := os.Stat(path)
  18. if err != nil {
  19. w.WriteHeader(http.StatusNotFound)
  20. w.Write(inout.FileToBytes("templates/error.tmpl"))
  21. return
  22. }
  23. w.Write(inout.FileToBytes(path))
  24. return
  25. }
  26. }