Skip to content

Commit

Permalink
Replace chi.URLParam by request.PathValue
Browse files Browse the repository at this point in the history
  • Loading branch information
tfabritius committed Feb 17, 2024
1 parent cc3e092 commit 6e4ce7d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
11 changes: 5 additions & 6 deletions backend/server/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"regexp"
"strconv"

"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
"github.com/tfabritius/plainpage/model"
"github.com/tfabritius/plainpage/service"
Expand Down Expand Up @@ -60,7 +59,7 @@ func (App) getBreadcrumbs(urlPath string, page *model.Page, folder *model.Folder
}

func (app App) getContent(w http.ResponseWriter, r *http.Request) {
urlPath := chi.URLParam(r, "*")
urlPath := r.PathValue("*")

userID := ctxutil.UserID(r.Context())
page := ctxutil.Page(r.Context())
Expand Down Expand Up @@ -122,7 +121,7 @@ func (app App) getContent(w http.ResponseWriter, r *http.Request) {
}

func (app App) patchContent(w http.ResponseWriter, r *http.Request) {
urlPath := chi.URLParam(r, "*")
urlPath := r.PathValue("*")

page := ctxutil.Page(r.Context())
folder := ctxutil.Folder(r.Context())
Expand Down Expand Up @@ -194,7 +193,7 @@ func (app App) patchContent(w http.ResponseWriter, r *http.Request) {
}

func (app App) putContent(w http.ResponseWriter, r *http.Request) {
urlPath := chi.URLParam(r, "*")
urlPath := r.PathValue("*")

page := ctxutil.Page(r.Context())
folder := ctxutil.Folder(r.Context())
Expand Down Expand Up @@ -252,7 +251,7 @@ func (app App) putContent(w http.ResponseWriter, r *http.Request) {
}

func (app App) deleteContent(w http.ResponseWriter, r *http.Request) {
urlPath := chi.URLParam(r, "*")
urlPath := r.PathValue("*")

page := ctxutil.Page(r.Context())
folder := ctxutil.Folder(r.Context())
Expand Down Expand Up @@ -285,7 +284,7 @@ func (app App) deleteContent(w http.ResponseWriter, r *http.Request) {
}

func (app App) getAttic(w http.ResponseWriter, r *http.Request) {
urlPath := chi.URLParam(r, "*")
urlPath := r.PathValue("*")
queryRev := r.URL.Query().Get("rev")

page := ctxutil.Page(r.Context())
Expand Down
3 changes: 1 addition & 2 deletions backend/server/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package server
import (
"net/http"

"github.com/go-chi/chi/v5"
"github.com/tfabritius/plainpage/model"
"github.com/tfabritius/plainpage/service"
"github.com/tfabritius/plainpage/service/ctxutil"
Expand Down Expand Up @@ -41,7 +40,7 @@ func (app App) RequireAdminPermission(next http.Handler) http.Handler {

func (app App) RetrieveContentMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
urlPath := chi.URLParam(r, "*")
urlPath := r.PathValue("*")

validUrl := isValidUrl(urlPath)

Expand Down
7 changes: 3 additions & 4 deletions backend/server/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"net/http"

"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
"github.com/tfabritius/plainpage/model"
"github.com/tfabritius/plainpage/service"
Expand All @@ -22,7 +21,7 @@ func (app App) getUsers(w http.ResponseWriter, r *http.Request) {
}

func (app App) getUser(w http.ResponseWriter, r *http.Request) {
username := chi.URLParam(r, "username")
username := r.PathValue("username")

user, err := app.Users.GetByUsername(username)
if errors.Is(err, model.ErrNotFound) {
Expand Down Expand Up @@ -94,7 +93,7 @@ func (app App) postUser(w http.ResponseWriter, r *http.Request) {
}

func (app App) patchUser(w http.ResponseWriter, r *http.Request) {
username := chi.URLParam(r, "username")
username := r.PathValue("username")
userID := ctxutil.UserID(r.Context())

isAdmin := app.isAdmin(userID)
Expand Down Expand Up @@ -165,7 +164,7 @@ func (app App) patchUser(w http.ResponseWriter, r *http.Request) {
}

func (app App) deleteUser(w http.ResponseWriter, r *http.Request) {
username := chi.URLParam(r, "username")
username := r.PathValue("username")
userID := ctxutil.UserID(r.Context())

isAdmin := app.isAdmin(userID)
Expand Down

0 comments on commit 6e4ce7d

Please sign in to comment.