1
0
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:
Vishal Rana 2015-11-15 12:08:12 -08:00
parent 1f8ecfd610
commit cba2724de3
3 changed files with 19 additions and 17 deletions

24
echo.go
View File

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

View File

@ -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()

View File

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