Skip to content

Commit

Permalink
Merge pull request #17 from xushiwei/redirect
Browse files Browse the repository at this point in the history
ctx.Redirect
  • Loading branch information
xushiwei authored Jan 15, 2024
2 parents 7b81477 + d2032c2 commit 607a356
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
# vendor/

# Go workspace file
go.work
go.work*
10 changes: 10 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ func acceptNext(accept string) (item, left string) {
return
}

// Redirect replies to the request with a redirect to url,
// which may be a path relative to the request path.
func (p *Context) Redirect(url string, code ...int) {
statusCode := http.StatusFound
if code == nil {
statusCode = code[0]
}
http.Redirect(p.ResponseWriter, p.Request, url, statusCode)
}

func (p *Context) TEXT(code int, mime string, text string) {
w := p.ResponseWriter
h := w.Header()
Expand Down

0 comments on commit 607a356

Please sign in to comment.