Added Redirect function
This commit is contained in:
parent
3f303d8e09
commit
1f62562d70
3 changed files with 22 additions and 0 deletions
|
@ -9,6 +9,7 @@ type Context interface {
|
|||
Bytes([]byte) error
|
||||
Error(...any) error
|
||||
Next() error
|
||||
Redirect(int, string) error
|
||||
Request() Request
|
||||
Response() Response
|
||||
Status(int) Context
|
||||
|
@ -51,6 +52,14 @@ func (ctx *context) Next() error {
|
|||
return ctx.server.handlers[ctx.handlerCount](ctx)
|
||||
}
|
||||
|
||||
// Redirect redirects the client to a different location
|
||||
// with the specified status code.
|
||||
func (ctx *context) Redirect(status int, location string) error {
|
||||
ctx.response.SetStatus(status)
|
||||
ctx.response.SetHeader("Location", location)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Request returns the HTTP request.
|
||||
func (ctx *context) Request() Request {
|
||||
return &ctx.request
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue