docs: add panic conditions documentation for SetMode and Redirect.Render

This commit is contained in:
xingzihai 2026-03-30 04:44:29 +00:00
parent d3ffc99852
commit 0fd0eab2e9
2 changed files with 2 additions and 0 deletions

View File

@ -55,6 +55,7 @@ func init() {
}
// SetMode sets gin mode according to input string.
// It panics if the value is not a valid gin mode (debug, release, or test).
func SetMode(value string) {
if value == "" {
if flag.Lookup("test.v") != nil {

View File

@ -17,6 +17,7 @@ type Redirect struct {
}
// Render (Redirect) redirects the http request to new location and writes redirect response.
// It panics if the status code is not a valid redirect status code (300-308, except 201).
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))