Initial commit: Open sourcing all of the Maple Open Technologies code.

This commit is contained in:
Bartlomiej Mika 2025-12-02 14:33:08 -05:00
commit 755d54a99d
2010 changed files with 448675 additions and 0 deletions

View file

@ -0,0 +1,29 @@
// codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/interface/http/middleware/url.go
package middleware
import (
"context"
"net/http"
"strings"
)
// URLProcessorMiddleware Middleware will split the full URL path into slash-sperated parts and save to
// the context to flow downstream in the app for this particular request.
func (mid *middleware) URLProcessorMiddleware(fn http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// Split path into slash-separated parts, for example, path "/foo/bar"
// gives p==["foo", "bar"] and path "/" gives p==[""]. Our API starts with
// "/api", as a result we will start the array slice at "1".
p := strings.Split(r.URL.Path, "/")[1:]
// log.Println(p) // For debugging purposes only.
// Open our program's context based on the request and save the
// slash-seperated array from our URL path.
ctx := r.Context()
ctx = context.WithValue(ctx, "url_split", p)
// Flow to the next middleware.
fn(w, r.WithContext(ctx))
}
}