mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-17 05:42:09 +08:00
feat(gin,runserver): go fmt file
This commit is contained in:
parent
72be513b9f
commit
a1f4f8406c
22
gin.go
22
gin.go
@ -297,19 +297,19 @@ func (engine *Engine) Run(addr ...string) (err error) {
|
||||
|
||||
// Run attaches the router to a http.Server and starts listening and serving HTTP requests.
|
||||
// You can use your http.server config like ReadTimeout ...
|
||||
// It is a shortcut for http.ListenAndServe(addr, router)
|
||||
// It is a shortcut for server.ListenAndServe()
|
||||
// Note: this method will block the calling goroutine indefinitely unless an error happens.
|
||||
func (engine *Engine) RunServer(server *http.Server, addr ...string) (err error) {
|
||||
defer func() { debugPrintError(err) }()
|
||||
|
||||
address := resolveAddress(addr)
|
||||
debugPrint("Listening and serving HTTP on %s\n", address)
|
||||
if len(addr) > 0 || server.Addr == ""{
|
||||
server.Addr = address
|
||||
}
|
||||
server.Handler = engine
|
||||
err = server.ListenAndServe()
|
||||
return
|
||||
defer func() { debugPrintError(err) }()
|
||||
|
||||
address := resolveAddress(addr)
|
||||
debugPrint("Listening and serving HTTP on %s\n", address)
|
||||
if len(addr) > 0 || server.Addr == "" {
|
||||
server.Addr = address
|
||||
}
|
||||
server.Handler = engine
|
||||
err = server.ListenAndServe()
|
||||
return
|
||||
}
|
||||
|
||||
// RunTLS attaches the router to a http.Server and starts listening and serving HTTPS (secure) requests.
|
||||
|
@ -60,13 +60,13 @@ func TestRunServer(t *testing.T) {
|
||||
service := &http.Server{}
|
||||
go func() {
|
||||
router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
|
||||
assert.NoError(t, router.RunServer(service,":8090"))
|
||||
assert.NoError(t, router.RunServer(service, ":8090"))
|
||||
}()
|
||||
// have to wait for the goroutine to start and run the server
|
||||
// otherwise the main thread will complete
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
|
||||
assert.Error(t, router.RunServer(service,":8090"))
|
||||
|
||||
assert.Error(t, router.RunServer(service, ":8090"))
|
||||
testRequest(t, "http://localhost:8090/example")
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user