remove path

This commit is contained in:
Mohamad Tahir 2023-10-30 17:03:25 +03:00
parent cabcbbb166
commit 7a03599d16
Signed by: MohamadTahir
GPG Key ID: 116FAB02D35512FA

View File

@ -10,7 +10,6 @@ import (
type Path struct { type Path struct {
Base string `json:"base,omitempty"` Base string `json:"base,omitempty"`
Path string `json:"path,omitempty"`
} }
type Config struct { type Config struct {
@ -71,11 +70,10 @@ func (a *UsersBlocker) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
} }
for _, path := range a.paths { for _, path := range a.paths {
blockedPath := path.Base + path.Path isPathMatched := strings.HasPrefix(req.URL.Path, path.Base)
isPathBlocked := strings.HasPrefix(req.URL.Path, blockedPath)
if isPathBlocked { if isPathMatched {
message := fmt.Sprintf("blocked path %s (matched with %s) for user %s", req.URL.Path, blockedPath, userId) message := fmt.Sprintf("blocked path %s (matched with %s) for user %s", req.URL.Path, path.Base, userId)
os.Stdout.WriteString(message) os.Stdout.WriteString(message)
http.Error(rw, message, http.StatusForbidden) http.Error(rw, message, http.StatusForbidden)
return return