mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-15 04:57:07 +08:00
Add Redirect to Context
This commit is contained in:
parent
c3abaf9afc
commit
5f06c7525a
12
context.go
12
context.go
@ -4,11 +4,12 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
"github.com/gin-gonic/gin/render"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -124,6 +125,13 @@ func (c *Context) Fail(code int, err error) {
|
||||
c.Abort(code)
|
||||
}
|
||||
|
||||
// Redirect replies to the request with a redirect to url,
|
||||
// which may be a path relative to the request path.
|
||||
func (c *Context) Redirect(urlStr string) {
|
||||
http.Redirect(c.Writer, c.Request, urlStr, http.StatusFound)
|
||||
c.Abort(-1) // About with code < 0, so that don't WriteHeader twice.
|
||||
}
|
||||
|
||||
func (c *Context) ErrorTyped(err error, typ uint32, meta interface{}) {
|
||||
c.Errors = append(c.Errors, errorMsg{
|
||||
Err: err.Error(),
|
||||
|
Loading…
x
Reference in New Issue
Block a user