mirror of
https://github.com/gin-gonic/gin.git
synced 2025-12-15 14:17:03 +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.
|
// Run attaches the router to a http.Server and starts listening and serving HTTP requests.
|
||||||
// You can use your http.server config like ReadTimeout ...
|
// 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.
|
// Note: this method will block the calling goroutine indefinitely unless an error happens.
|
||||||
func (engine *Engine) RunServer(server *http.Server, addr ...string) (err error) {
|
func (engine *Engine) RunServer(server *http.Server, addr ...string) (err error) {
|
||||||
defer func() { debugPrintError(err) }()
|
defer func() { debugPrintError(err) }()
|
||||||
|
|
||||||
address := resolveAddress(addr)
|
address := resolveAddress(addr)
|
||||||
debugPrint("Listening and serving HTTP on %s\n", address)
|
debugPrint("Listening and serving HTTP on %s\n", address)
|
||||||
if len(addr) > 0 || server.Addr == ""{
|
if len(addr) > 0 || server.Addr == "" {
|
||||||
server.Addr = address
|
server.Addr = address
|
||||||
}
|
}
|
||||||
server.Handler = engine
|
server.Handler = engine
|
||||||
err = server.ListenAndServe()
|
err = server.ListenAndServe()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunTLS attaches the router to a http.Server and starts listening and serving HTTPS (secure) requests.
|
// 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{}
|
service := &http.Server{}
|
||||||
go func() {
|
go func() {
|
||||||
router.GET("/example", func(c *Context) { c.String(http.StatusOK, "it worked") })
|
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
|
// have to wait for the goroutine to start and run the server
|
||||||
// otherwise the main thread will complete
|
// otherwise the main thread will complete
|
||||||
time.Sleep(5 * time.Millisecond)
|
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")
|
testRequest(t, "http://localhost:8090/example")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user