1// Copyright 2014 Manu Martinez-Almeida.  All rights reserved.
2// Use of this source code is governed by a MIT style
3// license that can be found in the LICENSE file.
4
5package render
6
7import (
8	"fmt"
9	"net/http"
10)
11
12type Redirect struct {
13	Code     int
14	Request  *http.Request
15	Location string
16}
17
18func (r Redirect) Render(w http.ResponseWriter) error {
19	// todo(thinkerou): go1.6 not support StatusPermanentRedirect(308)
20	// when we upgrade go version we can use http.StatusPermanentRedirect
21	if (r.Code < 300 || r.Code > 308) && r.Code != 201 {
22		panic(fmt.Sprintf("Cannot redirect with status code %d", r.Code))
23	}
24	http.Redirect(w, r.Request, r.Location, r.Code)
25	return nil
26}
27
28func (r Redirect) WriteContentType(http.ResponseWriter) {}
29