github.com/hellobchain/third_party@v0.0.0-20230331131523-deb0478a2e52/gin/render/redirect.go (about) 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 5 package render 6 7 import ( 8 "fmt" 9 "github.com/hellobchain/newcryptosm/http" 10 ) 11 12 // Redirect contains the http request reference and redirects status code and location. 13 type Redirect struct { 14 Code int 15 Request *http.Request 16 Location string 17 } 18 19 // Render (Redirect) redirects the http request to new location and writes redirect response. 20 func (r Redirect) Render(w http.ResponseWriter) error { 21 if (r.Code < http.StatusMultipleChoices || r.Code > http.StatusPermanentRedirect) && r.Code != http.StatusCreated { 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 28 // WriteContentType (Redirect) don't write any ContentType. 29 func (r Redirect) WriteContentType(http.ResponseWriter) {}