mirror of
https://github.com/gin-gonic/gin.git
synced 2026-01-11 00:56:57 +08:00
Merge e666eceaee05962220e16018b545666191694ca6 into 214a746b1d531cdacdcc0aa4039da119d4002837
This commit is contained in:
commit
5759d5fe87
13
gin.go
13
gin.go
@ -232,6 +232,19 @@ func iterate(path, method string, routes RoutesInfo, root *node) RoutesInfo {
|
||||
return routes
|
||||
}
|
||||
|
||||
// RunCustom, run server by a net.Listener
|
||||
// the main usage is to test, by a custom net.Listener we can let os to choose a free
|
||||
// port and get it.
|
||||
//
|
||||
// r := gin.Default()
|
||||
// l, err := net.Listen(":0")
|
||||
// l.Addr()
|
||||
// r.RunCustom(l)
|
||||
func (engine *Engine) RunCustom(l net.Listener) error {
|
||||
debugPrint("Listening and serving HTTP on %s\n", l.Addr())
|
||||
return http.Serve(l, engine)
|
||||
}
|
||||
|
||||
// Run attaches the router to a http.Server and starts listening and serving HTTP requests.
|
||||
// It is a shortcut for http.ListenAndServe(addr, router)
|
||||
// Note: this method will block the calling goroutine indefinitely unless an error happens.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user