add logging for URL redirection in main.go

This commit is contained in:
2025-06-16 15:47:33 +08:00
parent b8ee7551aa
commit a356ca4f49

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"github.com/cloudwego/hertz/pkg/app" "github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/app/server" "github.com/cloudwego/hertz/pkg/app/server"
"github.com/cloudwego/hertz/pkg/common/hlog"
"strings" "strings"
) )
@ -31,7 +32,9 @@ func main() {
} }
} }
} }
oldURL := scheme + "://" + host + string(c.Request.RequestURI())
newURL := scheme + "://" + newHost + string(c.Request.RequestURI()) newURL := scheme + "://" + newHost + string(c.Request.RequestURI())
hlog.Infof("Redirecting from %s to %s", oldURL, newURL)
c.Redirect(301, []byte(newURL)) c.Redirect(301, []byte(newURL))
c.Abort() c.Abort()
return return