Added redirect method
This commit is contained in:
@ -16,6 +16,7 @@ type Context interface {
|
||||
File(string) error
|
||||
Get(string) string
|
||||
Next() error
|
||||
Redirect(int, string) error
|
||||
Request() Request
|
||||
Response() Response
|
||||
Status(int) Context
|
||||
@ -94,6 +95,13 @@ func (ctx *ctx) Response() Response {
|
||||
return &ctx.response
|
||||
}
|
||||
|
||||
// Redirect sets the Location header and writes the headers with the given status code.
|
||||
func (ctx *ctx) Redirect(code int, url string) error {
|
||||
ctx.Response().SetHeader("Location", url)
|
||||
ctx.Status(code)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Status sets the HTTP status of the response.
|
||||
func (ctx *ctx) Status(status int) Context {
|
||||
ctx.response.WriteHeader(status)
|
||||
|
Reference in New Issue
Block a user