diff --git a/main.go b/main.go index c10d07d..a238a6c 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "fmt" "log" "net/http" "os" @@ -55,6 +56,8 @@ func lookupHandler(ctx context.Context, coll *mongo.Collection) func(w http.Resp return } + slug, locationCompartment, _ := strings.Cut(slug, "-") + if match := regexValid.MatchString(slug); !match { counterInvalidSlug.Inc() @@ -84,6 +87,11 @@ func lookupHandler(ctx context.Context, coll *mongo.Collection) func(w http.Resp redirURL = strings.Replace(redirectFound, "%s", doc.ID.Hex(), 1) } + if locationCompartment != "" { + // always expecting 0 query elements, not parsing as URL and dumb appending + redirURL += fmt.Sprintf("?locationCompartment=%s", locationCompartment) + } + http.Redirect(w, r, redirURL, 302) log.Printf("Redirecting %s to %s\n", slug, redirURL) }