help redirect
This commit is contained in:
15
main.go
15
main.go
@@ -38,6 +38,8 @@ var (
|
||||
redirectFound = os.Getenv("GOREDIRECT_FOUND")
|
||||
redirectNotFound = os.Getenv("GOREDIRECT_NOT_FOUND")
|
||||
redirectNoPath = os.Getenv("GOREDIRECT_NOPATH")
|
||||
redirectHelpKey = os.Getenv("GOREDIRECT_HELP_KEY")
|
||||
redirectHelpRedirect = os.Getenv("GOREDIRECT_HELP_URL")
|
||||
)
|
||||
|
||||
func lookupHandler(ctx context.Context, coll *mongo.Collection) func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -56,6 +58,15 @@ func lookupHandler(ctx context.Context, coll *mongo.Collection) func(w http.Resp
|
||||
return
|
||||
}
|
||||
|
||||
if slug == redirectHelpKey {
|
||||
counterHelpRedirect.Inc()
|
||||
|
||||
log.Printf("Redirecting help key %s to %s\n", redirectHelpKey, redirectHelpRedirect)
|
||||
http.Redirect(w, r, redirectHelpRedirect, 302)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
slug, locationCompartment, _ := strings.Cut(slug, "-")
|
||||
|
||||
if match := regexValid.MatchString(slug); !match {
|
||||
@@ -106,6 +117,10 @@ var (
|
||||
Name: "goredirect_no_path",
|
||||
Help: "The total number of queries with no slug.",
|
||||
})
|
||||
counterHelpRedirect = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "goredirect_help_path",
|
||||
Help: "The total number of queries with help key redirect.",
|
||||
})
|
||||
counterInvalidSlug = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "goredirect_invalid_slug",
|
||||
Help: "The total number of queries that did not match regex.",
|
||||
|
||||
Reference in New Issue
Block a user