If gin would've used http.Server
, I could've just done the following:
// s is a http.Server instance
s.SetKeepAlivesEnabled(false)
But gin doesn't allow that. So, how do we accomplish this?
Comment From: bolshoy
:+1: could be especially useful for scalable REST servers, so single-request connections don't linger.
Comment From: manucorporat
https://github.com/gin-gonic/gin#custom-http-configuration
router := gin.Default()
s := &http.Server{
Addr: ":8080",
Handler: router, // < here Gin is attached to the HTTP server
// ReadTimeout: 10 * time.Second,
// WriteTimeout: 10 * time.Second,
// MaxHeaderBytes: 1 << 20,
}
s.SetKeepAlivesEnabled(false)
s.ListenAndServe()
Gin (muxer) and the HTTP server work at different layers of abstraction.
Comment From: oryband
@manucorporat amazing and simple. Thanks.
Comment From: palrohitg
@manucorporat would be great if we you can specify, how to configure the custom timeout in seconds example: it node.js we can specify the keepalive timeout in seconds.