doyyan
1
I am writing a Golang Plugin where I want to access the url that had been rewritten to in the URL rewrite trigger (simple or advanced).
Please can you point me to a code sample for that?
Our use case is we want to use that data in a JWT token that we are creating.
Best Regards
Ravi
Here’s a minimal example to log the rewritten path. It needs to be called from the ‘post’ middleware hook.
package main
import (
"log"
"net/http"
"github.com/TykTechnologies/tyk/ctx"
"github.com/davecgh/go-spew/spew"
)
// LogUrlRewriteTarget logs the final rewrite target
func LogUrlRewriteTarget(rw http.ResponseWriter, r *http.Request) {
if v := r.Context().Value(ctx.UrlRewriteTarget) ; v != nil {
log.Println(v)
} else {
log.Println("No Rewrite")
}
}
func main() {}