feat(gin,runserver): go fmt file

This commit is contained in:
yangqiuhua 2019-05-16 14:38:05 +08:00
parent 72be513b9f
commit a1f4f8406c
2 changed files with 14 additions and 14 deletions

22
gin.go
View File

@ -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.

View File

@ -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")
}