From a1f4f8406c7d5010abd1395f8cc0aa06bd9cb37c Mon Sep 17 00:00:00 2001 From: yangqiuhua <284751067@qq.com> Date: Thu, 16 May 2019 14:38:05 +0800 Subject: [PATCH] feat(gin,runserver): go fmt file --- gin.go | 22 +++++++++++----------- gin_integration_test.go | 6 +++--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/gin.go b/gin.go index eeb28222..ad2bb02d 100644 --- a/gin.go +++ b/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. diff --git a/gin_integration_test.go b/gin_integration_test.go index 40b6a5dd..d535b2c7 100644 --- a/gin_integration_test.go +++ b/gin_integration_test.go @@ -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") }