094f9a9105
* remove go1.6 support * remove build tag * remove todo * remove go1.6 support: https://github.com/gin-gonic/gin/pull/1383/commits * update readme * remove go1.7 support * fix embedmd error * test * revert it * revert it * remove context_17 * add pusher test * v1.4.0 rc1
30 lines
905 B
Go
30 lines
905 B
Go
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
|
|
// Use of this source code is governed by a MIT style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package render
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
// Redirect contains the http request reference and redirects status code and location.
|
|
type Redirect struct {
|
|
Code int
|
|
Request *http.Request
|
|
Location string
|
|
}
|
|
|
|
// Render (Redirect) redirects the http request to new location and writes redirect response.
|
|
func (r Redirect) Render(w http.ResponseWriter) error {
|
|
if (r.Code < http.StatusMultipleChoices || r.Code > http.StatusPermanentRedirect) && r.Code != http.StatusCreated {
|
|
panic(fmt.Sprintf("Cannot redirect with status code %d", r.Code))
|
|
}
|
|
http.Redirect(w, r.Request, r.Location, r.Code)
|
|
return nil
|
|
}
|
|
|
|
// WriteContentType (Redirect) don't write any ContentType.
|
|
func (r Redirect) WriteContentType(http.ResponseWriter) {}
|