Pass locationCompartment to Inventory
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Currently to avoid 'Invalid slug' in links, inventory ignores it for now.
This commit is contained in:
8
main.go
8
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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user