- With issues:
- Use the search tool before opening a new issue.
- Please provide source code and commit sha if you found a bug.
- Review existing issues and provide feedback or react to them.
Description
I would like the ability to configure the server's read/write timeout
definition
I am used to creating servers without a framework and creating a server like:
srv := &http.Server{
Addr: fmt.Sprintf(":%d", cfg.port), // port passed in from a flag
Handler: app.routes(), // custom function for returning the handlers using julienshmidt's httprouter
IdleTimeout: time.Minute,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
ErrorLog: slog.NewLogLogger(logger.Handler(), slog.LevelError),
}
I understand that gin.Default()
it includes a logger so that's fine. However, when looking through the documentation I don't find where to configure these values.
What I would like to see:
package main
import (
"github.com/gin-gonic/gin"
)
func main() {
g := gin.Default() // or g := gin.New()
g.GET("/hello/:name", func(c *gin.Context) {
c.String(200, "Hello %s", c.Param("name"))
})
srvConfig := &gin.ServerConfig{
Addr: fmt.Sprintf(":%d", cfg.port),
IdleTimeout: time.Minute,
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
}
g.Run(srvConfig)
}
Comment From: RedCrazyGhost
Currently, you can only handle configuration manually by personally writing http.Server
Please see Custom HTTP configuration