mirror of
https://github.com/labstack/echo.git
synced 2024-11-28 08:38:39 +02:00
Set echo as handler for Echo#RunServer*
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
1f8ecfd610
commit
cba2724de3
24
echo.go
24
echo.go
@ -467,24 +467,22 @@ func (e *Echo) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Server returns the internal *http.Server.
|
||||
func (e *Echo) Server(addr string) *http.Server {
|
||||
s := &http.Server{Addr: addr, Handler: e}
|
||||
if e.http2 {
|
||||
http2.ConfigureServer(s, nil)
|
||||
}
|
||||
return s
|
||||
}
|
||||
// func (e *Echo) Server(addr string) *http.Server {
|
||||
// s := &http.Server{Addr: addr, Handler: e}
|
||||
// if e.http2 {
|
||||
// http2.ConfigureServer(s, nil)
|
||||
// }
|
||||
// return s
|
||||
// }
|
||||
|
||||
// Run runs a server.
|
||||
func (e *Echo) Run(addr string) {
|
||||
s := e.Server(addr)
|
||||
e.run(s)
|
||||
e.run(&http.Server{Addr: addr})
|
||||
}
|
||||
|
||||
// RunTLS runs a server with TLS configuration.
|
||||
func (e *Echo) RunTLS(addr, crtFile, keyFile string) {
|
||||
s := e.Server(addr)
|
||||
e.run(s, crtFile, keyFile)
|
||||
e.run(&http.Server{Addr: addr}, crtFile, keyFile)
|
||||
}
|
||||
|
||||
// RunServer runs a custom server.
|
||||
@ -498,6 +496,10 @@ func (e *Echo) RunTLSServer(s *http.Server, crtFile, keyFile string) {
|
||||
}
|
||||
|
||||
func (e *Echo) run(s *http.Server, files ...string) {
|
||||
s.Handler = e
|
||||
if e.http2 {
|
||||
http2.ConfigureServer(s, nil)
|
||||
}
|
||||
if len(files) == 0 {
|
||||
log.Fatal(s.ListenAndServe())
|
||||
} else if len(files) == 2 {
|
||||
|
10
echo_test.go
10
echo_test.go
@ -400,11 +400,11 @@ func TestEchoHTTPError(t *testing.T) {
|
||||
assert.Equal(t, m, he.Error())
|
||||
}
|
||||
|
||||
func TestEchoServer(t *testing.T) {
|
||||
e := New()
|
||||
s := e.Server(":1323")
|
||||
assert.IsType(t, &http.Server{}, s)
|
||||
}
|
||||
// func TestEchoServer(t *testing.T) {
|
||||
// e := New()
|
||||
// s := e.Server(":1323")
|
||||
// assert.IsType(t, &http.Server{}, s)
|
||||
// }
|
||||
|
||||
// func TestStripTrailingSlash(t *testing.T) {
|
||||
// e := New()
|
||||
|
@ -8,7 +8,7 @@ menu:
|
||||
|
||||
### Handler path
|
||||
|
||||
`Context#Path()` returns the registered path for a handler, it can be used in the middleware for logging purpose.
|
||||
`Context.Path()` returns the registered path for a handler, it can be used in the middleware for logging purpose.
|
||||
|
||||
*Example*
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user