11
0

help redirect

This commit is contained in:
2026-07-26 02:08:27 +03:00
parent a8c16e00e4
commit 406a877eef

15
main.go
View File

@@ -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.",