chore: use http.Status* instead of hard code (#1482)

This commit is contained in:
田欧
2018-08-14 09:51:56 +08:00
committed by Bo-Yi Wu
parent 8aef947f6e
commit f45c928a15
20 changed files with 209 additions and 192 deletions

View File

@ -16,6 +16,8 @@ type Redirect struct {
}
func (r Redirect) Render(w http.ResponseWriter) error {
// todo(thinkerou): go1.6 not support StatusPermanentRedirect(308)
// when we upgrade go version we can use http.StatusPermanentRedirect
if (r.Code < 300 || r.Code > 308) && r.Code != 201 {
panic(fmt.Sprintf("Cannot redirect with status code %d", r.Code))
}

View File

@ -286,7 +286,7 @@ func TestRenderRedirect(t *testing.T) {
assert.NoError(t, err)
data1 := Redirect{
Code: 301,
Code: http.StatusMovedPermanently,
Request: req,
Location: "/new/location",
}
@ -296,7 +296,7 @@ func TestRenderRedirect(t *testing.T) {
assert.NoError(t, err)
data2 := Redirect{
Code: 200,
Code: http.StatusOK,
Request: req,
Location: "/new/location",
}