Change filepaths to use filepath.Join() where possible

This commit is contained in:
2025-01-19 20:07:32 +01:00
parent 6885dfbb38
commit 9feb16a8d8
7 changed files with 26 additions and 26 deletions

View File

@ -5,6 +5,7 @@ import (
"log"
"net/http"
"os"
"path/filepath"
"github.com/google/uuid"
b "streifling.com/jason/cpolis/cmd/backend"
@ -56,8 +57,8 @@ func ServeArticle(c *b.Config, db *b.DB) http.HandlerFunc {
return
}
articleAbsName := fmt.Sprint(c.ArticleDir, "/", article.UUID, ".md")
contentBytes, err := os.ReadFile(articleAbsName)
articlePath := filepath.Join(c.ArticleDir, fmt.Sprint(article.UUID, ".md"))
contentBytes, err := os.ReadFile(articlePath)
if err != nil {
log.Println(err)
http.Error(w, err.Error(), http.StatusInternalServerError)

View File

@ -5,6 +5,7 @@ import (
"log"
"net/http"
"os"
"path/filepath"
b "streifling.com/jason/cpolis/cmd/backend"
)
@ -42,6 +43,6 @@ func ServePDF(c *b.Config) http.HandlerFunc {
return
}
http.ServeFile(w, r, c.PDFDir+"/"+r.PathValue("id"))
http.ServeFile(w, r, filepath.Join(c.PDFDir, r.PathValue("id")))
}
}