Add Redirect to Context

This commit is contained in:
minghua 2014-07-21 17:35:43 +08:00
parent c3abaf9afc
commit 5f06c7525a

View File

@ -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(),