From 406a877eef72eabb8f395f25d5e4902485cf84af Mon Sep 17 00:00:00 2001 From: rasmus Date: Sun, 26 Jul 2026 02:08:27 +0300 Subject: [PATCH] help redirect --- main.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.go b/main.go index a238a6c..4365aca 100644 --- a/main.go +++ b/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.",