1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-20 03:17:04 +00:00

Implement a GetURI to get the full uri of a (named) route

This commit is contained in:
Makis Maropoulos
2016-06-02 19:22:36 +03:00
parent 79e984146e
commit 05b6723b19
5 changed files with 68 additions and 3 deletions

View File

@@ -13,9 +13,9 @@ func (ctx *Context) SetHeader(k string, v string) {
// Redirect redirect sends a redirect response the client
// accepts 2 parameters string and an optional int
// first parameter is the url to redirect
// second parameter is the http status should send, default is 302 (Temporary redirect), you can set it to 301 (Permant redirect), if that's nessecery
// second parameter is the http status should send, default is 307 (Temporary redirect), you can set it to 301 (Permant redirect), if that's nessecery
func (ctx *Context) Redirect(urlToRedirect string, statusHeader ...int) {
httpStatus := 302 // temporary redirect
httpStatus := StatusTemporaryRedirect // temporary redirect
if statusHeader != nil && len(statusHeader) > 0 && statusHeader[0] > 0 {
httpStatus = statusHeader[0]
}
@@ -24,6 +24,15 @@ func (ctx *Context) Redirect(urlToRedirect string, statusHeader ...int) {
ctx.StopExecution()
}
// RedirectTo does the same thing as Redirect but instead of receiving a uri or path it receives a route name
func (ctx *Context) RedirectTo(routeName string, args ...interface{}) {
s, ok := ctx.station.RouteByName(routeName).Parse(args...)
if ok {
ctx.Redirect(s, StatusTemporaryRedirect)
}
}
// Error handling
// NotFound emits an error 404 to the client, using the custom http errors