Skip to content

Instantly share code, notes, and snippets.

@pprishchepa
Created May 15, 2023 17:44
Show Gist options
  • Save pprishchepa/f78a0dc915e58a1a09cadd2141c6616f to your computer and use it in GitHub Desktop.
Save pprishchepa/f78a0dc915e58a1a09cadd2141c6616f to your computer and use it in GitHub Desktop.
Reproducing https://github.com/vearne/gin-timeout resp. code issue
package main
import (
"net/http"
"net/http/httptest"
"time"
"github.com/gin-gonic/gin"
timeout "github.com/vearne/gin-timeout"
)
func main() {
req, _ := http.NewRequest("GET", "https://foo.com", nil)
engine := gin.New()
engine.Use(timeout.Timeout(timeout.WithTimeout(10 * time.Second)))
engine.Use(func(c *gin.Context) {
c.Next()
println("middleware code: ", c.Writer.Status())
})
engine.NoRoute(func(c *gin.Context) {
c.Redirect(http.StatusMovedPermanently, "https://example.com")
})
rr := httptest.NewRecorder()
engine.ServeHTTP(rr, req)
println("response code: ", rr.Code)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment